Received: from eggs.gnu.org ([2001:4830:134:3::10]:41873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4mQY-0004Xq-GA for qemu-devel@nongnu.org; Thu, 01 Aug 2013 02:32:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V4mQS-0008LC-DL for qemu-devel@nongnu.org; Thu, 01 Aug 2013 02:31:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5643) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4mQS-0008Kz-5C for qemu-devel@nongnu.org; Thu, 01 Aug 2013 02:31:52 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r716VpaR022113 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 1 Aug 2013 02:31:51 -0400 From: Fam Zheng Date: Thu, 1 Aug 2013 14:31:35 +0800 Message-Id: <1375338695-670-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH] monitor: fix parsing of big int List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Luiz Capitulino , Fam Zheng We call strtoull(3) to parse a string to int. the range we can accept with our local variable "int64_t n" is (-9223372036854775808 ~ 9223372036854775807), but strtoull(3) can return (0 ~ 18446744073709551615UL). So when we pass a int from HMP within the range of 9223372036854775808 ~ 18446744073709551615, it's safely converted and implicitly casted to int64_t, so n is assigned a negative value, silently, which is incorrect. We can verify this by (HMP) block_set_io_throttle ide0-hd0 999999999999999999 0 0 0 0 0 (HMP) block_set_io_throttle ide0-hd0 9999999999999999999 0 0 0 0 0 bps and iops values must be 0 or greater (HMP) block_set_io_throttle ide0-hd0 99999999999999999999 0 0 0 0 0 number too large The first command succeeds, the second is reporting a negative value error, the third command has correct prompt. Fix it by calling strtoll instead, which will report ERANGE as expected. (HMP) block_set_io_throttle ide0-hd0 999999999999999999 0 0 0 0 0 (HMP) block_set_io_throttle ide0-hd0 9999999999999999999 0 0 0 0 0 number too large (HMP) block_set_io_throttle ide0-hd0 99999999999999999999 0 0 0 0 0 number too large Signed-off-by: Fam Zheng --- monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.c b/monitor.c index 5dc0aa9..7bfb469 100644 --- a/monitor.c +++ b/monitor.c @@ -3286,7 +3286,7 @@ static int64_t expr_unary(Monitor *mon) break; default: errno = 0; - n = strtoull(pch, &p, 0); + n = strtoll(pch, &p, 0); if (errno == ERANGE) { expr_error(mon, "number too large"); } -- 1.8.3.4