From patchwork Mon Feb 4 18:27:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 218040 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 DD8402C02B3 for ; Tue, 5 Feb 2013 06:12:12 +1100 (EST) Received: from localhost ([::1]:44684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2Qky-0000TK-0s for incoming@patchwork.ozlabs.org; Mon, 04 Feb 2013 13:27:04 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2QkF-0006xg-B6 for qemu-devel@nongnu.org; Mon, 04 Feb 2013 13:26:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U2QkB-0002uB-J6 for qemu-devel@nongnu.org; Mon, 04 Feb 2013 13:26:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39116) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2QkB-0002th-Bo for qemu-devel@nongnu.org; Mon, 04 Feb 2013 13:26:15 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r14IQDon022512 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 4 Feb 2013 13:26:13 -0500 Received: from blackpad.lan.raisama.net (vpn1-7-242.gru2.redhat.com [10.97.7.242]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r14IQBCl011105; Mon, 4 Feb 2013 13:26:12 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id 47814200EAA; Mon, 4 Feb 2013 16:27:58 -0200 (BRST) From: Eduardo Habkost To: Anthony Liguori , qemu-devel@nongnu.org Date: Mon, 4 Feb 2013 16:27:46 -0200 Message-Id: <1360002472-17628-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1360002472-17628-1-git-send-email-ehabkost@redhat.com> References: <1360002472-17628-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Laszlo Ersek 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 Reviewed-by: Eric Blake --- vl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c index 3155989..0dae44c 100644 --- a/vl.c +++ b/vl.c @@ -1253,7 +1253,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;