"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

common/spl: fix potential out of buffer access in spl_fit_get_image_name function

The current code have two issues:
1) ineffective NULL pointer check

str = strchr(str, '\0') + 1
if (!str || ...

The str here will never be NULL (because we add 1 to result of strchr())

2) strchr() may go out of the buffer for the special forms of name variable.
It's better use memchr() function here.

According to the code the property is a sequence of C-string like
shown below:

'h', 'e', 'l', 'l', 'o', '\0', 'w', 'o', 'r', 'l', 'd', '\0', '!', '\0'

index is the string number we are interested, so

index = 0 => "hello",
index = 1 => "world",
index = 2 => "!"

The issue will arrise if last string for some reason have no terminating
'\0' character. This can happen for damaged or specially crafted dtb.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Reviewed-by: Tom Rini <trini@konsulko.com>

authored by

Mikhail Kshevetskiy and committed by
Tom Rini
3704b888 17012e30

+3 -2
+3 -2
common/spl/spl_fit.c
··· 86 86 87 87 str = name; 88 88 for (i = 0; i < index; i++) { 89 - str = strchr(str, '\0') + 1; 90 - if (!str || (str - name >= len)) { 89 + str = memchr(str, '\0', name + len - str); 90 + if (!str) { 91 91 found = false; 92 92 break; 93 93 } 94 + str++; 94 95 } 95 96 96 97 if (!found && CONFIG_IS_ENABLED(SYSINFO) && !sysinfo_get(&sysinfo)) {