Patchwork [6/8] vl.c: Use parse_uint_full() for NUMA nodeid

login
register
mail settings
Submitter Eduardo Habkost
Date Jan. 16, 2013, 6:28 p.m.
Message ID <1358360933-5323-7-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/212942/
State New
Headers show

Comments

Eduardo Habkost - Jan. 16, 2013, 6:28 p.m.
This should catch many kinds of errors that the current code wasn't
checking for:

 - Values that can't be parsed as a number
 - Negative values
 - Overflow
 - Empty string

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Eric Blake <eblake@redhat.com>

Changes v2:
 - Use base=10 to keep the existing behavior
---
 vl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Patch

diff --git a/vl.c b/vl.c
index b39cd9a..abc2af5 100644
--- a/vl.c
+++ b/vl.c
@@ -1264,7 +1264,10 @@  static void numa_add(const char *optarg)
         if (get_param_value(option, 128, "nodeid", optarg) == 0) {
             nodenr = nb_numa_nodes;
         } else {
-            nodenr = strtoull(option, NULL, 10);
+            if (parse_uint_full(option, &nodenr, 10) < 0) {
+                fprintf(stderr, "qemu: Invalid NUMA nodeid: %s\n", option);
+                exit(1);
+            }
         }
 
         if (nodenr >= MAX_NODES) {