From patchwork Thu Apr 26 23:37:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 155344 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 2247EB6FA3 for ; Fri, 27 Apr 2012 09:38:09 +1000 (EST) Received: from localhost ([::1]:44147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNYGE-0002NO-Kk for incoming@patchwork.ozlabs.org; Thu, 26 Apr 2012 19:38:06 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNYFl-0001IB-Px for qemu-devel@nongnu.org; Thu, 26 Apr 2012 19:37:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SNYFk-0002Qt-1V for qemu-devel@nongnu.org; Thu, 26 Apr 2012 19:37:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31762) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNYFj-0002Qk-OY for qemu-devel@nongnu.org; Thu, 26 Apr 2012 19:37:35 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3QNbXX6025971 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 26 Apr 2012 19:37:33 -0400 Received: from localhost (ovpn-113-104.phx2.redhat.com [10.3.113.104]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q3QNbWhf031665; Thu, 26 Apr 2012 19:37:32 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2012 20:37:40 -0300 Message-Id: <1335483461-31838-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1335483461-31838-1-git-send-email-lcapitulino@redhat.com> References: <1335483461-31838-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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");