Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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: cc00188 ("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>
  • Loading branch information
ebblake committed Jun 2, 2023
1 parent f49371e commit a73049b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions hw/core/numa.c
Expand Up @@ -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) {
Expand Down

0 comments on commit a73049b

Please sign in to comment.