Received: from eggs.gnu.org ([208.118.235.92]:54006) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SROcs-0005Uc-Dv for qemu-devel@nongnu.org; Mon, 07 May 2012 10:09:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SROcp-0001kl-GZ for qemu-devel@nongnu.org; Mon, 07 May 2012 10:09:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SROcp-0001kQ-8N for qemu-devel@nongnu.org; Mon, 07 May 2012 10:09:19 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q47E9HCj001648 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 May 2012 10:09:18 -0400 From: Luiz Capitulino Date: Mon, 7 May 2012 11:09:26 -0300 Message-Id: <1336399767-16248-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1336399767-16248-1-git-send-email-lcapitulino@redhat.com> References: <1336399767-16248-1-git-send-email-lcapitulino@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] hmp: expr_unary(): check for overflow in strtoul()/strtoull() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: amit.shah@redhat.com, qzhang@redhat.com, eblake@redhat.com, armbru@redhat.com 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 --- 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"); } -- 1.7.9.2.384.g4a92a