mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-21 20:34:38 +00:00
cmd: setexpr: fix printf_str()
If vsnprintf() returns a negative number, (i >= remaining) will
possibly be true:
'i' is of type signed int and 'remaining' is of the unsigned type size_t.
The C language will convert i to an unsigned type before the comparison.
This can result in the wrong error type being indicated.
Checking for negative i should be done first.
Fixes: f4f8d8bb1a
("cmd: setexpr: add format string handling")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
976fb2ffa3
commit
175e4b01be
1 changed files with 3 additions and 3 deletions
|
@ -144,10 +144,10 @@ static void printf_str(struct print_inf *inf, char *format, ...)
|
||||||
i = vsnprintf(inf->str + inf->offset, remaining, format, args);
|
i = vsnprintf(inf->str + inf->offset, remaining, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if (i >= remaining)
|
if (i < 0)
|
||||||
inf->error |= PRINT_TRUNCATED_ERROR;
|
|
||||||
else if (i < 0)
|
|
||||||
inf->error |= PRINT_CONVERSION_ERROR;
|
inf->error |= PRINT_CONVERSION_ERROR;
|
||||||
|
else if ((unsigned int)i >= remaining)
|
||||||
|
inf->error |= PRINT_TRUNCATED_ERROR;
|
||||||
else
|
else
|
||||||
inf->offset += i;
|
inf->offset += i;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue