zkey: Fix possible out of bounds access with malformed property files

When reading a properties file with a line containing a binary zero as first
character, an array access at index -1 is attempted, because strlen considers
this as an empty string (len = 0). The following array access 'line[len - 1]'
accesses the array at index -1.

Fix this by checking the line length and skip empty lines.

Reviewed-by: Finn Callies <fcallies@linux.ibm.com>
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Ingo Franzki
2026-06-11 17:42:21 +02:00
committed by Jan Höppner
parent c953486dec
commit c7ab70df2c

View File

@@ -386,6 +386,8 @@ int properties_load(struct properties *properties, const char *filename,
while (fgets(line, sizeof(line), fp) != NULL) {
len = strlen(line);
if (len == 0)
continue;
if (line[len - 1] == '\n')
line[len - 1] = '\0';
if (line[0] == '#')