[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 06/10] vl.c: handle invalid NUMA CPU ranges properly
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PATCH 06/10] vl.c: handle invalid NUMA CPU ranges properly |
Date: |
Fri, 11 Jan 2013 16:15:04 -0200 |
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 <address@hidden>
---
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)
--
1.7.11.7
- [Qemu-devel] [PATCH 00/10] -numa option parsing fixes & improvements, Eduardo Habkost, 2013/01/11
- [Qemu-devel] [PATCH 08/10] vl.c: Support multiple CPU ranges on -numa option, Eduardo Habkost, 2013/01/11
- [Qemu-devel] [PATCH 01/10] vl.c: Fix off-by-one bug when handling "-numa node" argument, Eduardo Habkost, 2013/01/11
- [Qemu-devel] [PATCH 06/10] vl.c: handle invalid NUMA CPU ranges properly,
Eduardo Habkost <=
- [Qemu-devel] [RFC 09/10] vl.c: Introduce QemuOpts-friendly "-numa-node" config option, Eduardo Habkost, 2013/01/11
- [Qemu-devel] [PATCH 03/10] vl.c: Isolate code specific to "-numa node" option type, Eduardo Habkost, 2013/01/11
- [Qemu-devel] [PATCH 04/10] vl.c: Check for NUMA node limit inside numa_node_add(), Eduardo Habkost, 2013/01/11
- [Qemu-devel] [PATCH 05/10] vl.c: Extract -numa "cpus" parsing to separate function, Eduardo Habkost, 2013/01/11
- [Qemu-devel] [RFC 10/10] vl.c: Handle legacy "-numa node, cpus=A, B, C, D" format, Eduardo Habkost, 2013/01/11
- [Qemu-devel] [PATCH 02/10] vl.c: Abort on unknown -numa option type, Eduardo Habkost, 2013/01/11