linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/4] lib: vsprintf: scanf: Negative number must have field width > 1
@ 2021-02-03 16:50 Richard Fitzgerald
  2021-02-03 16:50 ` [PATCH v4 2/4] lib: vsprintf: Fix handling of number field widths in vsscanf Richard Fitzgerald
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Richard Fitzgerald @ 2021-02-03 16:50 UTC (permalink / raw)
  To: pmladek, rostedt, sergey.senozhatsky, andriy.shevchenko, linux, shuah
  Cc: linux-kernel, linux-kselftest, patches, Richard Fitzgerald

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>
---
 lib/vsprintf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3b53c73580c5..28bb26cd1f67 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -3434,8 +3434,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


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-02-08 19:15 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 16:50 [PATCH v4 1/4] lib: vsprintf: scanf: Negative number must have field width > 1 Richard Fitzgerald
2021-02-03 16:50 ` [PATCH v4 2/4] lib: vsprintf: Fix handling of number field widths in vsscanf Richard Fitzgerald
2021-02-03 19:45   ` Andy Shevchenko
2021-02-04 16:35     ` Petr Mladek
2021-02-05 11:28       ` Richard Fitzgerald
2021-02-05 12:50         ` Andy Shevchenko
2021-02-05 15:23           ` David Laight
2021-02-05 15:53             ` Andy Shevchenko
2021-02-08 17:56           ` Petr Mladek
2021-02-08 11:47       ` Richard Fitzgerald
2021-02-03 16:50 ` [PATCH v4 3/4] lib: test_scanf: Add tests for sscanf number conversion Richard Fitzgerald
2021-02-03 19:47   ` Andy Shevchenko
2021-02-03 16:50 ` [PATCH v4 4/4] selftests: lib: Add wrapper script for test_scanf Richard Fitzgerald
2021-02-03 19:48   ` Andy Shevchenko
2021-02-03 19:48 ` [PATCH v4 1/4] lib: vsprintf: scanf: Negative number must have field width > 1 Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).