[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/21] numa: Check for qemu_strtosz_MiB error
From: |
Eric Blake |
Subject: |
[PULL 15/21] numa: Check for qemu_strtosz_MiB error |
Date: |
Thu, 1 Jun 2023 17:02:59 -0500 |
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>
---
hw/core/numa.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/hw/core/numa.c b/hw/core/numa.c
index d8d36b16d80..f08956ddb0f 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) {
--
2.40.1
- [PULL 07/21] cutils: Fix wraparound parsing in qemu_strtoui, (continued)
- [PULL 07/21] cutils: Fix wraparound parsing in qemu_strtoui, Eric Blake, 2023/06/01
- [PULL 09/21] cutils: Adjust signature of parse_uint[_full], Eric Blake, 2023/06/01
- [PULL 18/21] cutils: Set value in all integral qemu_strto* error paths, Eric Blake, 2023/06/01
- [PULL 16/21] test-cutils: Add more coverage to qemu_strtosz, Eric Blake, 2023/06/01
- [PULL 21/21] cutils: Improve qemu_strtosz handling of fractions, Eric Blake, 2023/06/01
- [PULL 04/21] test-cutils: Use g_assert_cmpuint where appropriate, Eric Blake, 2023/06/01
- [PULL 15/21] numa: Check for qemu_strtosz_MiB error,
Eric Blake <=
- [PULL 20/21] cutils: Improve qemu_strtod* error paths, Eric Blake, 2023/06/01
- [PULL 17/21] cutils: Set value in all qemu_strtosz* error paths, Eric Blake, 2023/06/01
- [PULL 06/21] test-cutils: Test more integer corner cases, Eric Blake, 2023/06/01
- [PULL 14/21] cutils: Allow NULL str in qemu_strtosz, Eric Blake, 2023/06/01
- [PULL 19/21] cutils: Use parse_uint in qemu_strtosz for negative rejection, Eric Blake, 2023/06/01
- [PULL 13/21] test-cutils: Refactor qemu_strtosz tests for less boilerplate, Eric Blake, 2023/06/01
- [PULL 12/21] test-cutils: Prepare for upcoming semantic change in qemu_strtosz, Eric Blake, 2023/06/01
- [PULL 03/21] test-cutils: Avoid g_assert in unit tests, Eric Blake, 2023/06/01
- Re: [PULL 00/21] NBD and miscellaneous patches for 2023-06-01, Richard Henderson, 2023/06/01