diff options
author | Richard Fitzgerald <rf@opensource.cirrus.com> | 2021-05-14 17:12:03 +0100 |
---|---|---|
committer | Petr Mladek <pmladek@suse.com> | 2021-05-19 15:05:11 +0200 |
commit | 11b3dda5e8b6cde957a6410233f30d6c48582998 (patch) | |
tree | dfd781d8fc3d44180d4691bdb5dc2215806d0406 /lib/vsprintf.c | |
parent | 7f3d08b255d1806502e45fe70ca2ba9646eb3aa1 (diff) | |
download | lwn-11b3dda5e8b6cde957a6410233f30d6c48582998.tar.gz lwn-11b3dda5e8b6cde957a6410233f30d6c48582998.zip |
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 <rf@opensource.cirrus.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20210514161206.30821-1-rf@opensource.cirrus.com
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r-- | lib/vsprintf.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 6c56c62fd9a5..af307588ad8b 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -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)) |