From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:41525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvXhv-0006vl-A5 for qemu-devel@nongnu.org; Wed, 16 Jan 2013 13:27:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvXht-0008JK-8h for qemu-devel@nongnu.org; Wed, 16 Jan 2013 13:27:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45061) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvXhs-0008Ik-VT for qemu-devel@nongnu.org; Wed, 16 Jan 2013 13:27:25 -0500 From: Eduardo Habkost Date: Wed, 16 Jan 2013 16:28:53 -0200 Message-Id: <1358360933-5323-9-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> Subject: [Qemu-devel] [PATCH 8/8] vl.c: validate -numa "cpus" parameter properly List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Anthony Liguori Cc: Chegu Vinod - 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 --- Cc: Eric Blake Changes v2: - Use base=10 to keep existing behavior --- vl.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/vl.c b/vl.c index d037193..73fefe6 100644 --- a/vl.c +++ b/vl.c @@ -1246,21 +1246,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) -- 1.7.11.7