summary refs log tree commit diff stats
path: root/hw/core/numa.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2023-05-22 14:04:35 -0500
committerEric Blake <eblake@redhat.com>2023-06-02 12:29:27 -0500
commita73049b2a1bad81c1059b79cf4567e4d6932634f (patch)
treee8a4a18755142c0df92b5eb1de3391ecceb42f95 /hw/core/numa.c
parentf49371ecae182eb07cfb105aa7ea637479d83764 (diff)
downloadfocaccia-qemu-a73049b2a1bad81c1059b79cf4567e4d6932634f.tar.gz
focaccia-qemu-a73049b2a1bad81c1059b79cf4567e4d6932634f.zip
numa: Check for qemu_strtosz_MiB error
As shown in the previous commit, qemu_strtosz_MiB sometimes leaves the
result value untouched (we have to audit further to learn that in that
case, the QAPI generator says that visit_type_NumaOptions() will have
zero-initialized it), and sometimes leaves it with the value of a
partial parse before -EINVAL occurs because of trailing garbage.
Rather than blindly treating any string the user may throw at us as
valid, we should check for parse failures.

Fixes: cc001888 ("numa: fixup parsed NumaNodeOptions earlier", v2.11.0)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Message-Id: <20230522190441.64278-14-eblake@redhat.com>
Diffstat (limited to 'hw/core/numa.c')
-rw-r--r--hw/core/numa.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/hw/core/numa.c b/hw/core/numa.c
index d8d36b16d8..f08956ddb0 100644
--- a/hw/core/numa.c
+++ b/hw/core/numa.c
@@ -531,10 +531,17 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
     /* Fix up legacy suffix-less format */
     if ((object->type == NUMA_OPTIONS_TYPE_NODE) && object->u.node.has_mem) {
         const char *mem_str = qemu_opt_get(opts, "mem");
-        qemu_strtosz_MiB(mem_str, NULL, &object->u.node.mem);
+        int ret = qemu_strtosz_MiB(mem_str, NULL, &object->u.node.mem);
+
+        if (ret < 0) {
+            error_setg_errno(&err, -ret, "could not parse memory size '%s'",
+                             mem_str);
+        }
     }
 
-    set_numa_options(ms, object, &err);
+    if (!err) {
+        set_numa_options(ms, object, &err);
+    }
 
     qapi_free_NumaOptions(object);
     if (err) {