From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=58456 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P49Ph-0006hC-GV for qemu-devel@nongnu.org; Fri, 08 Oct 2010 05:38:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P49Pg-0006WB-F6 for qemu-devel@nongnu.org; Fri, 08 Oct 2010 05:38:53 -0400 Received: from moutng.kundenserver.de ([212.227.126.171]:60515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P49Pg-0006W5-4h for qemu-devel@nongnu.org; Fri, 08 Oct 2010 05:38:52 -0400 Message-ID: <4CAEE698.8080705@mail.berlios.de> Date: Fri, 08 Oct 2010 11:38:32 +0200 From: Stefan Weil MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 3/7] Add more error handling to strtosz() References: <1286529360-5715-1-git-send-email-Jes.Sorensen@redhat.com> <1286529360-5715-4-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1286529360-5715-4-git-send-email-Jes.Sorensen@redhat.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jes.Sorensen@redhat.com Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com Am 08.10.2010 11:15, schrieb Jes.Sorensen@redhat.com: > From: Jes Sorensen > > Signed-off-by: Jes Sorensen > --- > cutils.c | 10 +++++++--- > 1 files changed, 7 insertions(+), 3 deletions(-) > > diff --git a/cutils.c b/cutils.c > index 0782032..e5a135e 100644 > --- a/cutils.c > +++ b/cutils.c > @@ -292,6 +292,7 @@ int fcntl_setfl(int fd, int flag) > ssize_t strtosz(const char *nptr, char **end) > { > ssize_t retval = -1; > + int64_t tmpval; > char *endptr; > int mul_required = 0; > double val, mul = 1; > @@ -301,9 +302,9 @@ ssize_t strtosz(const char *nptr, char **end) > mul_required = 1; > } > > + errno = 0; > val = strtod(nptr,&endptr); > - > - if (val< 0) > + if (endptr == nptr || errno != 0 || val< 0) > goto fail; > See CODING_STYLE. > > switch (*endptr++) { > @@ -332,7 +333,10 @@ ssize_t strtosz(const char *nptr, char **end) > goto fail; > } > > - retval = (ssize_t)(val * mul); > + tmpval = (val * mul); > + if (tmpval>= ~(size_t)0) > + goto fail; > See CODING_STYLE. > + retval = tmpval; > > if (end) > *end = endptr; >