From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Luiz Capitulino 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> Subject: [Qemu-devel] [PULL 5/6] hmp: expr_unary(): check for overflow in strtoul()/strtoull() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aliguori@us.ibm.com Cc: qemu-devel@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"); } -- 1.7.9.2.384.g4a92a