From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:36585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RyNFc-0001l1-T0 for qemu-devel@nongnu.org; Fri, 17 Feb 2012 07:49:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RyNFY-0005Dp-8m for qemu-devel@nongnu.org; Fri, 17 Feb 2012 07:49:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:8691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RyNFX-0005Di-V6 for qemu-devel@nongnu.org; Fri, 17 Feb 2012 07:49:20 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1HCnJTv011397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 17 Feb 2012 07:49:19 -0500 From: Markus Armbruster References: <4F3D6966.8090401@redhat.com> <20120217100810.GB31366@redhat.com> Date: Fri, 17 Feb 2012 13:35:02 +0100 In-Reply-To: <20120217100810.GB31366@redhat.com> (Michael S. Tsirkin's message of "Fri, 17 Feb 2012 12:08:10 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH 2/2] pci: rewrite devaddr parsing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Eric Blake , qemu-devel@nongnu.org "Michael S. Tsirkin" 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 [[:]:] */ >> >> + 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. > 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. 2. Diffstat: 1 files changed, 38 insertions(+), 43 deletions(-) Why bother?