From patchwork Fri Apr 27 13:18:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 155477 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 F3FEBB6FA1 for ; Fri, 27 Apr 2012 23:18:58 +1000 (EST) Received: from localhost ([::1]:32807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNl4a-0003Gq-NR for incoming@patchwork.ozlabs.org; Fri, 27 Apr 2012 09:18:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44434) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNl4H-0002uA-1H for qemu-devel@nongnu.org; Fri, 27 Apr 2012 09:18:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SNl47-00020E-Il for qemu-devel@nongnu.org; Fri, 27 Apr 2012 09:18:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21367) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNl47-0001zs-B5 for qemu-devel@nongnu.org; Fri, 27 Apr 2012 09:18:27 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3RDIPGs020297 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 Apr 2012 09:18:25 -0400 Received: from localhost (ovpn-116-78.ams2.redhat.com [10.36.116.78]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3RDINQK016236; Fri, 27 Apr 2012 09:18:24 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 27 Apr 2012 10:18:31 -0300 Message-Id: <1335532712-11899-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1335532712-11899-1-git-send-email-lcapitulino@redhat.com> References: <1335532712-11899-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: amit.shah@redhat.com, peter.maydell@linaro.org, qzhang@redhat.com, eblake@redhat.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 1/2] 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 --- monitor.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/monitor.c b/monitor.c index 8946a10..56ee971 100644 --- a/monitor.c +++ b/monitor.c @@ -3120,10 +3120,17 @@ static int64_t expr_unary(Monitor *mon) n = 0; break; default: + errno = 0; #if TARGET_PHYS_ADDR_BITS > 32 n = strtoull(pch, &p, 0); + if (n == ULLONG_MAX && errno == ERANGE) { + expr_error(mon, "number too large"); + } #else n = strtoul(pch, &p, 0); + if (n == ULONG_MAX && errno == ERANGE) { + expr_error(mon, "number too large"); + } #endif if (pch == p) { expr_error(mon, "invalid char in expression");