From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=46333 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3rys-0008Sx-UI for qemu-devel@nongnu.org; Thu, 07 Oct 2010 11:02:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P3rys-0005Em-2s for qemu-devel@nongnu.org; Thu, 07 Oct 2010 11:02:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P3ryr-0005EL-SE for qemu-devel@nongnu.org; Thu, 07 Oct 2010 11:02:02 -0400 From: Jes.Sorensen@redhat.com Date: Thu, 7 Oct 2010 17:01:47 +0200 Message-Id: <1286463710-28262-4-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1286463710-28262-1-git-send-email-Jes.Sorensen@redhat.com> References: <1286463710-28262-1-git-send-email-Jes.Sorensen@redhat.com> Subject: [Qemu-devel] [PATCH 3/6] Add more error handling to strtosz() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, armbru@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..012eb11 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; 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; + retval = tmpval; if (end) *end = endptr; -- 1.7.2.3