From patchwork Mon Feb 4 18:27:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 218028 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 AF5F72C02B3 for ; Tue, 5 Feb 2013 05:26:48 +1100 (EST) Received: from localhost ([::1]:41630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2Qkg-0007I5-LQ for incoming@patchwork.ozlabs.org; Mon, 04 Feb 2013 13:26:46 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2QkG-0006xw-2Z for qemu-devel@nongnu.org; Mon, 04 Feb 2013 13:26:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U2QkC-0002uX-3N for qemu-devel@nongnu.org; Mon, 04 Feb 2013 13:26:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58018) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2QkB-0002uF-Qe for qemu-devel@nongnu.org; Mon, 04 Feb 2013 13:26:16 -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 r14IQEvs022523 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 4 Feb 2013 13:26:14 -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 r14IQDSj011116; Mon, 4 Feb 2013 13:26:14 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id C05B2203EF2; Mon, 4 Feb 2013 16:27:59 -0200 (BRST) From: Eduardo Habkost To: Anthony Liguori , qemu-devel@nongnu.org Date: Mon, 4 Feb 2013 16:27:52 -0200 Message-Id: <1360002472-17628-9-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 8/8] vl.c: validate -numa "cpus" parameter properly 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 - Accept empty strings without aborting - Use parse_uint*() to parse numbers - Abort if anything except '-' or end-of-string is found after the first number. - Check for endvalue < value Also change the MAX_CPUMASK_BITS warning message from "A max of %d CPUs are supported in a guest" to "qemu: NUMA: A max of %d VCPUs are supported". Signed-off-by: Eduardo Habkost Reviewed-by: Eric Blake --- vl.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/vl.c b/vl.c index de164f8..a8dc73d 100644 --- a/vl.c +++ b/vl.c @@ -1249,21 +1249,43 @@ static void numa_node_parse_cpus(int nodenr, const char *cpus) char *endptr; unsigned long long value, endvalue; - value = strtoull(cpus, &endptr, 10); + /* Empty CPU range strings will be considered valid, they will simply + * not set any bit in the CPU bitmap. + */ + if (!*cpus) { + return; + } + + if (parse_uint(cpus, &value, &endptr, 10) < 0) { + goto error; + } if (*endptr == '-') { - endvalue = strtoull(endptr+1, &endptr, 10); - } else { + if (parse_uint_full(endptr + 1, &endvalue, 10) < 0) { + goto error; + } + } else if (*endptr == '\0') { endvalue = value; + } else { + goto error; } - if (!(endvalue < MAX_CPUMASK_BITS)) { + if (endvalue >= MAX_CPUMASK_BITS) { endvalue = MAX_CPUMASK_BITS - 1; fprintf(stderr, - "A max of %d CPUs are supported in a guest\n", + "qemu: NUMA: A max of %d VCPUs are supported\n", MAX_CPUMASK_BITS); } + if (endvalue < value) { + goto error; + } + bitmap_set(node_cpumask[nodenr], value, endvalue-value+1); + return; + +error: + fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus); + exit(1); } static void numa_add(const char *optarg)