From patchwork Fri Jan 11 18:15:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 211394 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 E958A2C032C for ; Sat, 12 Jan 2013 05:14:11 +1100 (EST) Received: from localhost ([::1]:37598 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ttj7J-0001cr-US for incoming@patchwork.ozlabs.org; Fri, 11 Jan 2013 13:14:09 -0500 Received: from eggs.gnu.org ([208.118.235.92]:45991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ttj6s-0001Tj-RY for qemu-devel@nongnu.org; Fri, 11 Jan 2013 13:13:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ttj6q-00032j-TJ for qemu-devel@nongnu.org; Fri, 11 Jan 2013 13:13:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:63294) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ttj6q-00032K-LI for qemu-devel@nongnu.org; Fri, 11 Jan 2013 13:13:40 -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 r0BIDcMl018380 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 11 Jan 2013 13:13:38 -0500 Received: from blackpad.lan.raisama.net (vpn1-7-42.gru2.redhat.com [10.97.7.42]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0BIDbSr022373; Fri, 11 Jan 2013 13:13:38 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id B41CE202B53; Fri, 11 Jan 2013 16:15:19 -0200 (BRST) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 11 Jan 2013 16:15:04 -0200 Message-Id: <1357928108-21066-7-git-send-email-ehabkost@redhat.com> In-Reply-To: <1357928108-21066-1-git-send-email-ehabkost@redhat.com> References: <1357928108-21066-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: libvir-list@redhat.com, Chegu Vinod , Anthony Liguori Subject: [Qemu-devel] [PATCH 06/10] vl.c: handle invalid NUMA CPU ranges 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 Add checks for the following cases: * Empty string: will be ignored and won't set any CPU bitmap, parser won't abort. * Missing end value after "-": parser will abort. * Extra characters after a valid CPU range: parser will abort. * "N-M" string where M < N: parser will abort. Signed-off-by: Eduardo Habkost --- vl.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c index 03a826e..19010fa 100644 --- a/vl.c +++ b/vl.c @@ -1057,13 +1057,30 @@ static void numa_node_parse_cpus(int nodenr, const char *cpus) char *endptr; unsigned long long value, endvalue; + /* Empty strings will be ignored, and not considered an error */ + if (!*cpus) { + return; + } + value = strtoull(cpus, &endptr, 10); if (*endptr == '-') { - endvalue = strtoull(endptr+1, &endptr, 10); + endptr++; + if (!*endptr) { + goto error; + } + endvalue = strtoull(endptr, &endptr, 10); } else { endvalue = value; } + if (*endptr != '\0') { + goto error; + } + + if (endvalue < value) { + goto error; + } + if (!(endvalue < MAX_CPUMASK_BITS)) { endvalue = MAX_CPUMASK_BITS - 1; fprintf(stderr, "A max of %d CPUs are supported in a guest\n", @@ -1071,6 +1088,11 @@ static void numa_node_parse_cpus(int nodenr, const char *cpus) } 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_node_add(const char *optarg)