Skip to contentSkip to conversation

tests/qtest: Fix potential NULL pointer dereference in qos_build_main_args()

PATCH Applied AlexChen 3 participants 3 messages Nov 3, 2020

lore
Share & tools
lore

AlexChen

author
#0 lore raw

PATCH 1/1 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.

---
 tests/qtest/fuzz/qos_fuzz.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qtest/fuzz/qos_fuzz.c +2 -1
index b943577b8c..cee1a2a60f 100644
@@ -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;
Signature · 1 line
2.19.1
#1 lore raw
Quoted 25 lines · AlexChen

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.

---
 tests/qtest/fuzz/qos_fuzz.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qtest/fuzz/qos_fuzz.c +1 -1
index b943577b8c..cee1a2a60f 100644
@@ -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) {

tests/qtest/fuzz/qos_fuzz.c static GString *qos_build_main_args(void) · line 85

Quoted 7 lines
tests/qtest/fuzz/qos_fuzz.c +1 -0
@@ -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;

Queued, thanks.

Paolo

Reviewed-by on v1 1/1
#2 lore raw
In reply to AlexChen
Quoted 6 lines · AlexChen

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.

Thanks

Quoted 27 lines
---
 tests/qtest/fuzz/qos_fuzz.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qtest/fuzz/qos_fuzz.c +2 -1
index b943577b8c..cee1a2a60f 100644
@@ -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;
Signature · 1 line
2.19.1