From patchwork Tue May 8 17:50:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 157764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CC7ADB6F62 for ; Wed, 9 May 2012 04:02:31 +1000 (EST) Received: from localhost ([::1]:48957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRoZ5-0006H0-QO for incoming@patchwork.ozlabs.org; Tue, 08 May 2012 13:51:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRoYS-0004JF-CS for qemu-devel@nongnu.org; Tue, 08 May 2012 13:50:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SRoYL-0002dm-IG for qemu-devel@nongnu.org; Tue, 08 May 2012 13:50:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49008) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRoYL-0002cs-9p for qemu-devel@nongnu.org; Tue, 08 May 2012 13:50:25 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q48HoNce000642 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 May 2012 13:50:23 -0400 Received: from localhost (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q48HoLsc020523; Tue, 8 May 2012 13:50:22 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Tue, 8 May 2012 14:50:17 -0300 Message-Id: <1336499418-12722-6-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1336499418-12722-1-git-send-email-lcapitulino@redhat.com> References: <1336499418-12722-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 5/6] hmp: expr_unary(): check for overflow in strtoul()/strtoull() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It's not checked currently, so something like: (qemu) balloon -100000000000001111114334234 (qemu) Will just "work" (in this case the balloon command will get a random value). Fix it by checking if strtoul()/strtoull() overflowed. Signed-off-by: Luiz Capitulino Reviewed-by: Eric Blake --- monitor.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/monitor.c b/monitor.c index 8946a10..bf60984 100644 --- a/monitor.c +++ b/monitor.c @@ -3120,11 +3120,15 @@ static int64_t expr_unary(Monitor *mon) n = 0; break; default: + errno = 0; #if TARGET_PHYS_ADDR_BITS > 32 n = strtoull(pch, &p, 0); #else n = strtoul(pch, &p, 0); #endif + if (errno == ERANGE) { + expr_error(mon, "number too large"); + } if (pch == p) { expr_error(mon, "invalid char in expression"); }