diff mbox series

[v8,RESEND,1/4] lib: vsprintf: scanf: Negative number must have field width > 1

Message ID 20210514161206.30821-1-rf@opensource.cirrus.com
State Accepted
Commit 11b3dda5e8b6cde957a6410233f30d6c48582998
Headers show
Series [v8,RESEND,1/4] lib: vsprintf: scanf: Negative number must have field width > 1 | expand

Commit Message

Richard Fitzgerald May 14, 2021, 4:12 p.m. UTC
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>
---
 lib/vsprintf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Petr Mladek May 20, 2021, 8:35 a.m. UTC | #1
On Fri 2021-05-14 17:12:03, Richard Fitzgerald wrote:
> 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>


The entrire patchset has been committed into print/linux.git,
branch for-5.14-vsprintf-scanf.

Thanks for reminder. I am sorry. It somehow fallen from my radar.

Best Regards,
Petr
diff mbox series

Patch

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))