From: "Michael S. Tsirkin" <mst@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] pci: rewrite devaddr parsing
Date: Sun, 19 Feb 2012 22:03:43 +0200 [thread overview]
Message-ID: <20120219200343.GA24464@redhat.com> (raw)
In-Reply-To: <m3ehttmydl.fsf@blackfin.pond.sub.org>
On Fri, Feb 17, 2012 at 01:35:02PM +0100, Markus Armbruster wrote:
> "Michael S. Tsirkin" <mst@redhat.com> writes:
>
> > On Thu, Feb 16, 2012 at 01:39:02PM -0700, Eric Blake wrote:
> >> On 02/16/2012 12:23 PM, malc wrote:
> >> > On Thu, 16 Feb 2012, Michael S. Tsirkin wrote:
> >> >
> >> >> Use scanf instead of manual string scanning.
> >> >>
> >> >> +
> >> >> + /* Parse [[<domain>:]<bus>:]<slot> */
> >> >> + sscanf(addr, "%x:%x:%x%n", &dom, &bus, &slot, &n);
> >> >
> >> > sscanf can fail.
> >>
> >> Worse, the *scanf family has undefined behavior on integer overflow. If
> >> addr contains "100000000000000:0:0", there's no telling whether it will
> >> be diagnosed as a parse error, or silently accepted and truncated, in
> >> which case, there's no telling what dom will contain.
> >>
> >> I cringe any time I see someone using scanf to parse numbers from
> >> arbitrary user input; I barely tolerate it for parsing things generated
> >> by the kernel, but even there, I won't ever use scanf myself.
> >> Same goes
> >> for atoi. _Only_ strtol and friends can robustly parse arbitrary input
> >> into integers.
> >
> > Seems easy to fix: I'll just set maximum field width of 8.
>
> Nope. Functional change: "000000001.2" is no longer accepted.
OK, there's an easy way to fix with
%*[0]%8x
> > Any other issues?
>
> Yes.
>
> 1. More functional changes, e.g.
>
> * "1" is no longer rejected when funcp != NULL
>
> Probably more. I'd be particularly wary of sscanf()'s appetite for
> space.
BTW strtoul that we currently use skips whitespace
silently too. We probably should validate input with
%*[0-9a-f.:] beforehand to address this.
> 2. Diffstat: 1 files changed, 38 insertions(+), 43 deletions(-)
>
> Why bother?
next prev parent reply other threads:[~2012-02-19 20:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-16 18:15 [Qemu-devel] [PATCH 0/2] pci devaddr parsing cleanups Michael S. Tsirkin
2012-02-16 18:15 ` [Qemu-devel] [PATCH 1/2] pci: don't export an internal function Michael S. Tsirkin
2012-02-16 18:15 ` [Qemu-devel] [PATCH 2/2] pci: rewrite devaddr parsing Michael S. Tsirkin
2012-02-16 19:23 ` malc
2012-02-16 20:39 ` Eric Blake
2012-02-16 21:35 ` malc
2012-02-17 10:08 ` Michael S. Tsirkin
2012-02-17 12:35 ` Markus Armbruster
2012-02-19 16:10 ` Michael S. Tsirkin
2012-02-19 20:03 ` Michael S. Tsirkin [this message]
2012-02-17 9:42 ` Michael S. Tsirkin
2012-02-17 9:50 ` malc
2012-02-17 10:13 ` Michael S. Tsirkin
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=20120219200343.GA24464@redhat.com \
--to=mst@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=qemu-devel@nongnu.org \
/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;
as well as URLs for NNTP newsgroup(s).