tools: Fix potential null-deref with result of strtok_r
authorMaks Mishin <maks.mishinfz@gmail.com>
Sun, 9 Feb 2025 15:46:21 +0000 (18:46 +0300)
committerTom Rini <trini@konsulko.com>
Tue, 18 Feb 2025 22:32:24 +0000 (16:32 -0600)
Return value of a function 'strtok_r' is dereferenced at kwbimage.c:1655
without checking for NULL, but it is usually checked for this function.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
tools/kwbimage.c

index d1cbced..3dcf5ba 100644 (file)
@@ -1653,6 +1653,12 @@ static int image_create_config_parse_oneline(char *line,
        char *unknown_msg = "Ignoring unknown line '%s'\n";
 
        keyword = strtok_r(line, delimiters, &saveptr);
+
+       if (!keyword) {
+               fprintf(stderr, "Parameter missing in line '%s'\n", line);
+               return -1;
+       }
+
        keyword_id = recognize_keyword(keyword);
 
        if (!keyword_id) {