From patchwork Thu Aug 1 06:31:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 263925 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 339212C00BF for ; Thu, 1 Aug 2013 16:32:20 +1000 (EST) Received: from localhost ([::1]:58131 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4mQq-0004ZC-P0 for incoming@patchwork.ozlabs.org; Thu, 01 Aug 2013 02:32:16 -0400 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 Received: from T430s.nay.redhat.com ([10.66.6.13]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r716Vlf8002998; Thu, 1 Aug 2013 02:31:49 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 1 Aug 2013 14:31:35 +0800 Message-Id: <1375338695-670-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Luiz Capitulino , Fam Zheng Subject: [Qemu-devel] [PATCH] monitor: fix parsing of big int 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 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"); }