Skip to contentSkip to conversation

t-runner: Fix mem leak with sim keys

PATCH In review Tim Kourt 2 participants 8 messages Oct 22, 2019 – Oct 23, 2019

lore
Share & tools
lore

Tim Kourt

author
#0 lore raw

PATCH 1/7 t-runner: Fix mem leak with sim keys

Use l_settings_get_value instead of l_settings_get_string to prevent unnecessary memory duplication.

---
 tools/test-runner.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/test-runner.c +2 -2
index 4551c6c1..430e18e3 100644
@@ -1961,8 +1961,8 @@ static void create_network_and_run_tests(void *data, void *user_data)
 						HW_CONFIG_SETUP_TMPFS_EXTRAS,
 									':');
 
-	sim_keys = l_settings_get_string(hw_settings, HW_CONFIG_GROUP_SETUP,
-			"sim_keys");
+	sim_keys = l_settings_get_value(hw_settings, HW_CONFIG_GROUP_SETUP,
+								"sim_keys");
 
 	if (sim_keys) {
 		if (!strcmp(sim_keys, "ofono")) {
Signature · 1 line
2.13.6
author
#1 lore raw

PATCH 2/7 t-runner: Fix mem leak caused by unclosed dir

---
 tools/test-runner.c | 2 ++
 1 file changed, 2 insertions(+)
tools/test-runner.c +2 -0
index 430e18e3..5045984c 100644
@@ -2413,6 +2413,8 @@ next:
 		l_free(unit_test_abs_path);
 	}
 
+	closedir(d);
+
 exit:
 	l_strfreev(unit_tests);
 }
Signature · 1 line
2.13.6
author
#2 lore raw

PATCH 3/7 t-runner: Fix mem leak caused by python test names

In reply to Tim Kourt
---
 tools/test-runner.c | 2 ++
 1 file changed, 2 insertions(+)
tools/test-runner.c +2 -0
index 5045984c..faa5dfa1 100644
@@ -1089,6 +1089,8 @@ static bool add_path(const char *path, int level, struct l_queue *config_queue)
 		l_queue_insert(config_queue, entry, insert_test_entry, NULL);
 	}
 
+	l_queue_destroy(py_test_queue, l_free);
+
 	closedir(dir);
 	return true;
 }
Signature · 1 line
2.13.6
author
#3 lore raw

PATCH 4/7 t-runner: Fix out-of-bounds write

In reply to Tim Kourt
---
 tools/test-runner.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/test-runner.c +1 -1
index faa5dfa1..2dc19726 100644
@@ -1636,7 +1636,7 @@ static void print_test_status(char *test_name, enum test_status ts,
 
 	interval_str = l_malloc(int_len);
 	memset(interval_str, ' ', int_len);
-	interval_str[int_len] = '\0';
+	interval_str[int_len - 1] = '\0';
 
 	if (interval > 0)
 		sprintf(interval_str, "%.3f sec", interval);
Signature · 1 line
2.13.6
author
#4 lore raw

PATCH 5/7 t-runner: Fix possible assignment of NULL pointer

In reply to Tim Kourt
---
 tools/test-runner.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/test-runner.c +2 -1
index 2dc19726..0226dd15 100644
@@ -2674,7 +2674,8 @@ static void run_tests(void)
 		test_action_str = ptr + 4;
 
 		ptr = strchr(test_action_str, '\'');
-		*ptr = '\0';
+		if (ptr)
+			*ptr = '\0';
 
 		if (!strcmp(test_action_str, "virtual"))
 			native_hw = false;
Signature · 1 line
2.13.6
author
#5 lore raw

PATCH 6/7 t-runner: Check for NULL before using strcmp

In reply to Tim Kourt
---
 tools/test-runner.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/test-runner.c +3 -3
index 0226dd15..398494e6 100644
@@ -2957,9 +2957,9 @@ int main(int argc, char *argv[])
 			break;
 		case 'g':
 			gdb_opt = optarg;
-			if (!(!strcmp(gdb_opt, "iwd") ||
-					!strcmp(gdb_opt, "hostapd") ||
-					!strcmp(gdb_opt, "hwsim"))) {
+			if (!gdb_opt || (strcmp(gdb_opt, "iwd") &&
+					strcmp(gdb_opt, "hostapd") &&
+					strcmp(gdb_opt, "hwsim"))) {
 				l_error("--gdb can only be used with iwd"
 					", hwsim or hostapd");
 				return EXIT_FAILURE;
Signature · 1 line
2.13.6
author
#6 lore raw

PATCH 7/7 t-runner: Check for errors after opening file

In reply to Tim Kourt
---
 tools/test-runner.c | 3 +++
 1 file changed, 3 insertions(+)
tools/test-runner.c +3 -0
index 398494e6..1dfdb9af 100644
@@ -524,6 +524,9 @@ static pid_t execute_program(char *argv[], char *envp[], bool wait,
 							S_IRUSR | S_IWUSR);
 			}
 
+			if (fd == -1)
+				exit(EXIT_FAILURE);
+
 			dup2(fd, 1);
 			dup2(fd, 2);
 
Signature · 1 line
2.13.6
#7 lore raw
In reply to Tim Kourt

Hi Tim,

Quoted 6 lines · Tim Kourt

Use l_settings_get_value instead of l_settings_get_string to prevent unnecessary memory duplication.

---
  tools/test-runner.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

All applied, thanks.

Regards,
-Denis