From: Petr Mladek <pmladek@suse.com>
To: Richard Fitzgerald <rf@opensource.cirrus.com>
Cc: rostedt@goodmis.org, sergey.senozhatsky@gmail.com,
shuah@kernel.org, patches@opensource.cirrus.com,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
Stanislaw Gruszka <stf_xl@wp.pl>,
Kalle Valo <kvalo@codeaurora.org>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH v3 1/4] lib: vsprintf: scanf: Negative number must have field width > 1
Date: Mon, 21 Dec 2020 16:16:01 +0100 [thread overview]
Message-ID: <X+C8MeYHX0/FsPwS@alley> (raw)
In-Reply-To: <20201217180057.23786-1-rf@opensource.cirrus.com>
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
parent reply other threads:[~2020-12-21 15:16 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20201217180057.23786-1-rf@opensource.cirrus.com>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=X+C8MeYHX0/FsPwS@alley \
--to=pmladek@suse.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=kvalo@codeaurora.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=rf@opensource.cirrus.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.com \
--cc=shuah@kernel.org \
--cc=stf_xl@wp.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox