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>
This commit is contained in:
AlexChen 2020-11-03 22:53:09 +08:00 committed by Paolo Bonzini
parent 3569a5dfc1
commit c59c582d56

View File

@ -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;