Skip to content

Commit 2127613

Browse files
Realloc() needs one more byte for sprintf()
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>
1 parent d44405e commit 2127613

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

generate_sbat_var_defs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ readfile(char *SbatLevel_Variable)
5757
fgets(line, sizeof(line), varfilep) != NULL) {
5858
char *new = NULL;
5959
new = realloc(revlistentry->revocations,
60-
revocationsp + strlen(line) + 1);
60+
revocationsp + strlen(line) + 2);
6161
if (new == NULL) {
6262
ret = -1;
6363
goto err;

0 commit comments

Comments
 (0)