Skip to content

Commit 11b3dda

Browse files
rfvirgilpmladek
authored andcommitted
lib: vsprintf: scanf: Negative number must have field width > 1
If a signed number field starts with a '-' the field width must be > 1, or unlimited, to allow at least one digit after the '-'. This patch adds a check for this. If a signed field starts with '-' and field_width == 1 the scanf will quit. It is ok for a signed number field to have a field width of 1 if it starts with a digit. In that case the single digit can be converted. Signed-off-by: Richard Fitzgerald <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7f3d08b commit 11b3dda

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/vsprintf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3526,8 +3526,12 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
35263526
str = skip_spaces(str);
35273527

35283528
digit = *str;
3529-
if (is_sign && digit == '-')
3529+
if (is_sign && digit == '-') {
3530+
if (field_width == 1)
3531+
break;
3532+
35303533
digit = *(str + 1);
3534+
}
35313535

35323536
if (!digit
35333537
|| (base == 16 && !isxdigit(digit))

0 commit comments

Comments
 (0)