Commit 11b3dda5 authored by Richard Fitzgerald's avatar Richard Fitzgerald Committed by Petr Mladek

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: default avatarRichard Fitzgerald <rf@opensource.cirrus.com>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Acked-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20210514161206.30821-1-rf@opensource.cirrus.com
parent 7f3d08b2
...@@ -3526,8 +3526,12 @@ int vsscanf(const char *buf, const char *fmt, va_list args) ...@@ -3526,8 +3526,12 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
str = skip_spaces(str); str = skip_spaces(str);
digit = *str; digit = *str;
if (is_sign && digit == '-') if (is_sign && digit == '-') {
if (field_width == 1)
break;
digit = *(str + 1); digit = *(str + 1);
}
if (!digit if (!digit
|| (base == 16 && !isxdigit(digit)) || (base == 16 && !isxdigit(digit))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment