From patchwork Thu Oct 7 15:01:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 67065 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B31E7B70AA for ; Fri, 8 Oct 2010 02:05:32 +1100 (EST) Received: from localhost ([127.0.0.1]:38861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3s2D-0001cf-T2 for incoming@patchwork.ozlabs.org; Thu, 07 Oct 2010 11:05:29 -0400 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 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o97F1xkn015904 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 7 Oct 2010 11:01:59 -0400 Received: from localhost6.localdomain6 (ovpn-113-90.phx2.redhat.com [10.3.113.90]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o97F1s1N021634; Thu, 7 Oct 2010 11:01:58 -0400 From: Jes.Sorensen@redhat.com To: qemu-devel@nongnu.org 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> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: pbonzini@redhat.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 3/6] Add more error handling to strtosz() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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;