hostmem: fix crash when querying empty host-nodes property via QMP
PATCH 1/1 hostmem: fix crash when querying empty host-nodes property via QMP
QEMU will crashes with
qapi/qobject-output-visitor.c:210: qobject_output_complete: Assertion `qov->root && ((&qov->stack)->slh_first == ((void *)0))' failed
when trying to get value of empty hostmem.host-nodes property.
Fix it by calling visitor even if host-nodes wasn't set before exiting from property getter to return empty list.
--- backends/hostmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
backends/hostmem.c +2 -1
@@ -86,7 +86,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, value =find_first_bit (backend->host_nodes,MAX_NODES );if (value ==MAX_NODES ) { -return ; + goto ret; } *node =g_malloc0 (sizeof (**node));
@@ -104,6 +104,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, node = &(*node)->next; }while (true); +ret:visit_type_uint16List (v, name, &host_nodes, errp); }
Signature · 1 line
2.7.4
Quoted 26 lines · On Tue, 5 Feb 2019 15:31:27 +0100 Igor Mammedov <[email protected]> wrote:
QEMU will crashes with
qapi/qobject-output-visitor.c:210:qobject_output_complete: Assertion `qov->root && ((&qov->stack)->slh_first == ((void *)0))' failed
when trying to get value of empty hostmem.host-nodes property.Fix it by calling visitor even if host-nodes wasn't set before exiting from property getter to return empty list.
Signed-off-by Igor Mammedov <[email protected]>--- backends/hostmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)backends/hostmem.c +1
-1@@ -86,7 +86,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, value =find_first_bit (backend->host_nodes,MAX_NODES );if (value ==MAX_NODES ) { -return ; + goto ret; } *node =g_malloc0 (sizeof (**node));
backends/hostmem.c host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, · line 110
Quoted 7 lines
backends/hostmem.c +1
-0@@ -104,6 +104,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, node = &(*node)->next; }while (true); +ret:visit_type_uint16List (v, name, &host_nodes, errp); }
Markus/Michael,
does this patch make sense from QAPI point of view?
Quoted 6 lines · Igor Mammedov
QEMU will crashes with
qapi/qobject-output-visitor.c:210:qobject_output_complete: Assertion `qov->root && ((&qov->stack)->slh_first == ((void *)0))' failed
when trying to get value of empty hostmem.host-nodes property.Fix it by calling visitor even if host-nodes wasn't set before exiting from property getter to return empty list.
host-nodes or host_nodes?
If local variable host_nodes: that one's always set. The case you fix has it set to NULL.
Quoted 19 lines
Signed-off-by Igor Mammedov <[email protected]>--- backends/hostmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)backends/hostmem.c +1
-1@@ -86,7 +86,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, value =find_first_bit (backend->host_nodes,MAX_NODES );if (value ==MAX_NODES ) { -return ; + goto ret; } *node =g_malloc0 (sizeof (**node));
backends/hostmem.c host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, · line 109
Quoted 6 lines
backends/hostmem.c +1
-0@@ -104,6 +104,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, node = &(*node)->next; }while (true); +ret:visit_type_uint16List (v, name, &host_nodes, errp); }
Yes, an empty list needs to be visited just like a non-empty list.
Patch looks good.
Quoted 6 lines · On Wed, 13 Feb 2019 14:30:55 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 4 lines · Igor Mammedov
QEMU will crashes with
qapi/qobject-output-visitor.c:210:qobject_output_complete: Assertion `qov->root && ((&qov->stack)->slh_first == ((void *)0))' failed
when trying to get value of empty hostmem.host-nodes property.
Quoted 7 lines
Quoted 2 lines
Fix it by calling visitor even if host-nodes wasn't set before exiting from property getter to return empty list.
host-nodes or
host_nodes?If local variable
host_nodes: that one's always set. The case you fix has it set to NULL.
it's about property host-nodes:
value = find_first_bit(backend->host_nodes, MAX_NODES);
if (value == MAX_NODES) {
goto ret;
}when no bits set, it exits without visiting being returned list.
I'll send v2 with commit message giving more explanation to make it clearer.
Quoted 30 lines
Quoted 19 lines
Signed-off-by Igor Mammedov <[email protected]>--- backends/hostmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)backends/hostmem.c +1
-1@@ -86,7 +86,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, value =find_first_bit (backend->host_nodes,MAX_NODES );if (value ==MAX_NODES ) { -return ; + goto ret; } *node =g_malloc0 (sizeof (**node));backends/hostmem.c host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, · line 109
Quoted 6 lines
backends/hostmem.c +1
-0@@ -104,6 +104,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, node = &(*node)->next; }while (true); +ret:visit_type_uint16List (v, name, &host_nodes, errp); }Yes, an empty list needs to be visited just like a non-empty list.
Patch looks good.