Skip to contentSkip to conversation

tools: Fix potential null-deref with result of strtok_r

PATCH In review Maks Mishin 2 participants 2 messages Feb 9, 2025 – Feb 19, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: Fix potential null-deref with result of strtok_r

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.

---
 tools/kwbimage.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/kwbimage.c +6 -0
index d1cbced28f..3dcf5ba66b 100644
@@ -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) {
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · Maks Mishin

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.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom