From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ry8za-0000XR-PI for qemu-devel@nongnu.org; Thu, 16 Feb 2012 16:35:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ry8za-0004Pi-0o for qemu-devel@nongnu.org; Thu, 16 Feb 2012 16:35:54 -0500 Received: from fe02x03-cgp.akado.ru ([77.232.31.165]:65359 helo=akado.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ry8zZ-0004OP-Qz for qemu-devel@nongnu.org; Thu, 16 Feb 2012 16:35:53 -0500 Date: Fri, 17 Feb 2012 01:35:45 +0400 (MSK) From: malc In-Reply-To: <4F3D6966.8090401@redhat.com> Message-ID: References: <4F3D6966.8090401@redhat.com> 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: Eric Blake Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" On Thu, 16 Feb 2012, 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. To whomever wanted to apply this - don't. -- mailto:av1474@comtv.ru