From patchwork Wed Jan 16 18:28:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 212945 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 2D17B2C008D for ; Thu, 17 Jan 2013 05:28:52 +1100 (EST) Received: from localhost ([::1]:44926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvXiW-000051-Ok for incoming@patchwork.ozlabs.org; Wed, 16 Jan 2013 13:28:04 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvXhu-0006vE-7r for qemu-devel@nongnu.org; Wed, 16 Jan 2013 13:27:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvXhs-0008Iq-Qp for qemu-devel@nongnu.org; Wed, 16 Jan 2013 13:27:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvXhs-0008IO-JI for qemu-devel@nongnu.org; Wed, 16 Jan 2013 13:27:24 -0500 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 r0GIRMJv024114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 16 Jan 2013 13:27:22 -0500 Received: from blackpad.lan.raisama.net (vpn1-7-107.gru2.redhat.com [10.97.7.107]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0GIRL0E013225; Wed, 16 Jan 2013 13:27:21 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id 87322200E64; Wed, 16 Jan 2013 16:28:59 -0200 (BRST) From: Eduardo Habkost To: qemu-devel@nongnu.org, Anthony Liguori Date: Wed, 16 Jan 2013 16:28:47 -0200 Message-Id: <1358360933-5323-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1358360933-5323-1-git-send-email-ehabkost@redhat.com> References: <1358360933-5323-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Chegu Vinod Subject: [Qemu-devel] [PATCH 2/8] vl.c: Fix off-by-one bug when handling "-numa node" argument 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 The numa_add() code was unconditionally adding 1 to the get_opt_name() return value, making it point after the end of the string if no ',' separator is present. Example of weird behavior caused by the bug: $ qemu-img create -f qcow2 this-file-image-has,cpus=5,mem=1000,in-its-name.qcow2 5G Formatting 'this-file-image-has,cpus=5,mem=1000,in-its-name.qcow2', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 $ ./x86_64-softmmu/qemu-system-x86_64 -S -monitor stdio -numa node 'this-file-image-has,cpus=5,mem=1000,in-its-name.qcow2' QEMU 1.3.50 monitor - type 'help' for more information (qemu) info numa 1 nodes node 0 cpus: 0 node 0 size: 1000 MB (qemu) This changes the code to nove the pointer only if ',' is found. Signed-off-by: Eduardo Habkost --- vl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c index 15e0280..f29d926 100644 --- a/vl.c +++ b/vl.c @@ -1250,7 +1250,10 @@ static void numa_add(const char *optarg) value = endvalue = 0ULL; - optarg = get_opt_name(option, 128, optarg, ',') + 1; + optarg = get_opt_name(option, 128, optarg, ','); + if (*optarg == ',') { + optarg++; + } if (!strcmp(option, "node")) { if (get_param_value(option, 128, "nodeid", optarg) == 0) { nodenr = nb_numa_nodes;