Skip to content

Realloc() needs to allocate one more byte for sprintf() #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025

Conversation

dennis-tseng99
Copy link
Contributor

@dennis-tseng99 dennis-tseng99 commented Apr 15, 2025

In generate_sbat_var_defs.c, realloc() should allocate one more byte for the end of string '\0' when running sprintf() later. please also refer #744

Suppose we use fgets() to get line="abc\n", so strlen(line)=4 bytes. realloc(...,strlen(line),1) will allocate only 5 bytes which is not capable to save line(3 bytes),'\' and 'n'(2 bytes) pluses extra '\0' byte totally 6 bytes when running sprintf(.....,"%s\\n", line) later on.
where '\n' of line has been removed in line[strlen(line) - 1] = 0;

In generate_sbat_var_defs.c, realloc() should allocate one more byte for
the end of string '\0' when running sprintf() later.

Suppose we use fgets() to get line="abc\n", so strlen(line)=4 bytes.
realloc(...,strlen(line),1) will allocate 5 bytes which is not capable to
save line(3 bytes),'\' and 'n'(2 bytes) pluses extra '\0' byte totally 6 bytes
when running sprintf(.....,"%s\\n", line) later on.
where '\n' of line has been removed in line[strlen(line) - 1] = 0;

Signed-off-by: Dennis Tseng <[email protected]>
@vathpela vathpela merged commit 32804cf into rhboot:main Jun 3, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants