From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MSntf-00077n-GE for qemu-devel@nongnu.org; Mon, 20 Jul 2009 04:06:55 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MSntb-00076X-IX for qemu-devel@nongnu.org; Mon, 20 Jul 2009 04:06:55 -0400 Received: from [199.232.76.173] (port=53092 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MSntb-00076T-D3 for qemu-devel@nongnu.org; Mon, 20 Jul 2009 04:06:51 -0400 Received: from mx20.gnu.org ([199.232.41.8]:45211) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MSnta-0000ao-NF for qemu-devel@nongnu.org; Mon, 20 Jul 2009 04:06:50 -0400 Received: from mx2.redhat.com ([66.187.237.31]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MSntZ-0008QL-7J for qemu-devel@nongnu.org; Mon, 20 Jul 2009 04:06:49 -0400 Message-ID: <4A64254E.8030000@redhat.com> Date: Mon, 20 Jul 2009 10:05:34 +0200 From: Kevin Wolf MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] qemu-io: reject invalid pattern References: <20090719231925.GA1923@lst.de> In-Reply-To: <20090719231925.GA1923@lst.de> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Christoph Hellwig Cc: qemu-devel@nongnu.org Christoph Hellwig schrieb: > Replace the use of atoi which is used for pattern parsing currently with > strtol. Atoi won't parse sedecimal pattern values (it always returns 0), > but qemu-iotests use such pattern values. Also reject every pattern > that is not a unsigned char as we pass the pattern to memset which > expect a bye value (despite having the pattern argument declared as int). > > Based on an earlier patch by Stefan Weil which did not include the > error handling. > > > Signed-off-by: Christoph Hellwig > Reported-by: Stefan Weil > > Index: qemu/qemu-io.c > =================================================================== > --- qemu.orig/qemu-io.c 2009-07-20 00:59:41.616922630 +0200 > +++ qemu/qemu-io.c 2009-07-20 01:06:23.824900811 +0200 > @@ -26,6 +26,26 @@ static BlockDriverState *bs; > static int misalign; > > /* > + * Parse the pattern argument to various sub-commands. > + * > + * Because the pattern is used as an argument to memset it must evaluate > + * to an unsigned integer that fits into a single byte. + * Returns the pattern byte or -1 in case arg does not contain a valid pattern > + */ > +static int parse_pattern(const char *arg) > +{ > + char *endptr = NULL; > + long pattern; > + > + pattern = strtol(arg, &endptr, 0); > + if (pattern < 0 || pattern > UCHAR_MAX || *endptr != '\0') { > + printf("%s is not a valid pattern byte\n", arg); > + return -1; > + } > + > + return pattern; > +} > + > +/* > * Memory allocation helpers. > * > * Make sure memory is aligned by default, or purposefully misaligned if > @@ -304,7 +324,9 @@ read_f(int argc, char **argv) > break; > case 'P': > Pflag = 1; > - pattern = atoi(optarg); > + pattern = parse_pattern(optarg); > + if (pattern < 0) > + return 0; Coding style (braces). Looks good to me otherwise. Kevin