Skip to content

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 <dennis.tseng@suse.com>
@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