netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v3 1/4] lib: vsprintf: scanf: Negative number must have field width > 1
       [not found] <20201217180057.23786-1-rf@opensource.cirrus.com>
@ 2020-12-21 15:16 ` Petr Mladek
  0 siblings, 0 replies; only message in thread
From: Petr Mladek @ 2020-12-21 15:16 UTC (permalink / raw)
  To: Richard Fitzgerald
  Cc: rostedt, sergey.senozhatsky, shuah, patches, linux-kernel,
	linux-kselftest, Stanislaw Gruszka, Kalle Valo, David S. Miller,
	Jakub Kicinski, linux-wireless, netdev

On Thu 2020-12-17 18:00:54, 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.

The change makes perfect sense. vsscanf() should always process only one
character when the field width is 1.

Well, it has a potential to break existing users that rely on the
broken behavior. Fortunately, there seems be only one:

	drivers/net/wireless/intel/iwlegacy/3945-mac.c: if (sscanf(buf, "%1i", &ant) != 1) {

It is used to set a device parameter: il3945_mod_params.antenna.
There are three valid values:

	enum il3945_antenna {
		IL_ANTENNA_DIVERSITY,
		IL_ANTENNA_MAIN,
		IL_ANTENNA_AUX
	};

So, we should be on the safe side.

Anyway, adding people from
get_maintainer.pl drivers/net/wireless/intel/iwlegacy/3945-mac.c
so that they are aware of this.

> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

> ---
>  lib/vsprintf.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 14c9a6af1b23..8954ff94a53c 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -3433,8 +3433,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	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-21 15:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20201217180057.23786-1-rf@opensource.cirrus.com>
2020-12-21 15:16 ` [PATCH v3 1/4] lib: vsprintf: scanf: Negative number must have field width > 1 Petr Mladek

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