summary refs log tree commit diff stats
path: root/tests/qtest/fuzz/qos_fuzz.c
diff options
context:
space:
mode:
authorAlexChen <alex.chen@huawei.com>2020-11-03 22:53:09 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2020-11-03 10:15:43 -0500
commitc59c582d56ee3bbde15e6788c0d28329792b2573 (patch)
treeb07de13589b876742a213c93aa1415ec7a1ac5fb /tests/qtest/fuzz/qos_fuzz.c
parent3569a5dfc11f2c4880b7cddd9e0091b29aa0e015 (diff)
downloadfocaccia-qemu-c59c582d56ee3bbde15e6788c0d28329792b2573.tar.gz
focaccia-qemu-c59c582d56ee3bbde15e6788c0d28329792b2573.zip
tests/qtest: Fix potential NULL pointer dereference in qos_build_main_args()
In qos_build_main_args(), the pointer 'path' is dereferenced before
checking it is valid, which may lead to NULL pointer dereference.
So move the assignment to 'cmd_line' after checking 'path' is valid.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Alex Chen <alex.chen@huawei.com>
Message-Id: <5FA16ED5.4000203@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/qtest/fuzz/qos_fuzz.c')
-rw-r--r--tests/qtest/fuzz/qos_fuzz.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tests/qtest/fuzz/qos_fuzz.c b/tests/qtest/fuzz/qos_fuzz.c
index b943577b8c..cee1a2a60f 100644
--- a/tests/qtest/fuzz/qos_fuzz.c
+++ b/tests/qtest/fuzz/qos_fuzz.c
@@ -70,7 +70,7 @@ static GString *qos_build_main_args(void)
 {
     char **path = fuzz_path_vec;
     QOSGraphNode *test_node;
-    GString *cmd_line = g_string_new(path[0]);
+    GString *cmd_line;
     void *test_arg;
 
     if (!path) {
@@ -79,6 +79,7 @@ static GString *qos_build_main_args(void)
     }
 
     /* Before test */
+    cmd_line = g_string_new(path[0]);
     current_path = path;
     test_node = qos_graph_get_node(path[(g_strv_length(path) - 1)]);
     test_arg = test_node->u.test.arg;