]> Git Repo - linux.git/commitdiff
lib: vsprintf: scanf: Negative number must have field width > 1
authorRichard Fitzgerald <[email protected]>
Fri, 14 May 2021 16:12:03 +0000 (17:12 +0100)
committerPetr Mladek <[email protected]>
Wed, 19 May 2021 13:05:11 +0000 (15:05 +0200)
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]
lib/vsprintf.c

index 6c56c62fd9a50209b8be9094ad9cb5042619ec5a..af307588ad8b3387f4b3d61bd28cae8c813a833c 100644 (file)
@@ -3526,8 +3526,12 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
                str = skip_spaces(str);
 
                digit = *str;
-               if (is_sign && digit == '-')
+               if (is_sign && digit == '-') {
+                       if (field_width == 1)
+                               break;
+
                        digit = *(str + 1);
+               }
 
                if (!digit
                    || (base == 16 && !isxdigit(digit))
This page took 0.05535 seconds and 4 git commands to generate.