[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210330104558.16481-1-rf@opensource.cirrus.com>
Date: Tue, 30 Mar 2021 11:45:55 +0100
From: Richard Fitzgerald <rf@...nsource.cirrus.com>
To: <pmladek@...e.com>, <rostedt@...dmis.org>,
<sergey.senozhatsky@...il.com>,
<andriy.shevchenko@...ux.intel.com>, <linux@...musvillemoes.dk>,
<shuah@...nel.org>
CC: <linux-kernel@...r.kernel.org>, <linux-kselftest@...r.kernel.org>,
<patches@...nsource.cirrus.com>,
Richard Fitzgerald <rf@...nsource.cirrus.com>
Subject: [PATCH v8 1/4] 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@...nsource.cirrus.com>
Reviewed-by: Petr Mladek <pmladek@...e.com>
Acked-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
---
lib/vsprintf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 41ddc353ebb8..f78651e9b030 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -3466,8 +3466,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))
--
2.20.1
Powered by blists - more mailing lists