test-runner: Use l_strdup_printf to combine strings

There's a new "-Werror=format-overflow" warning in gcc 8 that detects
potential overflow or truncation with sprintf/snprintf, so the
test-runner build fails with gcc 8. Using l_strdup_printf allows the
build to succeed, and moves a few large buffers from the stack to the
heap.
This commit is contained in:
Mat Martineau 2018-05-09 15:48:33 -07:00 committed by Denis Kenzior
parent 46abfc7813
commit 9252d23358
1 changed files with 14 additions and 10 deletions

View File

@ -345,8 +345,8 @@ static bool check_virtualization(void)
static void start_qemu(void)
{
char cwd[PATH_MAX], initcmd[PATH_MAX], testargs[PATH_MAX];
char cmdline[CMDLINE_MAX];
char cwd[PATH_MAX], testargs[PATH_MAX];
char *initcmd, *cmdline;
char **argv;
int i, pos;
bool has_virt;
@ -357,9 +357,9 @@ static void start_qemu(void)
strcat(cwd, "/");
if (own_binary[0] == '/')
snprintf(initcmd, sizeof(initcmd), "%s", own_binary);
initcmd = l_strdup_printf("%s", own_binary);
else
snprintf(initcmd, sizeof(initcmd), "%s/%s", cwd, own_binary);
initcmd = l_strdup_printf("%s/%s", cwd, own_binary);
pos = snprintf(testargs, sizeof(testargs), "%s", test_argv[0]);
@ -370,7 +370,7 @@ static void start_qemu(void)
pos += snprintf(testargs + pos, len, " %s", test_argv[i]);
}
snprintf(cmdline, sizeof(cmdline),
cmdline = l_strdup_printf(
"console=ttyS0,115200n8 earlyprintk=serial "
"rootfstype=9p "
"root=/dev/root "
@ -408,6 +408,10 @@ static void start_qemu(void)
argv[pos] = NULL;
execve(argv[0], argv, qemu_envp);
/* Don't expect to reach here */
free(initcmd);
free(cmdline);
}
static pid_t execute_program(char *argv[], bool wait, bool verbose)
@ -1942,19 +1946,19 @@ static void test_stat_queue_entry_destroy(void *data)
static void run_auto_tests(void)
{
char test_home_path[PATH_MAX];
char env_path[PATH_MAX];
L_AUTO_FREE_VAR(char*, test_home_path);
L_AUTO_FREE_VAR(char*, env_path);
int i;
struct l_hashmap *test_config_map;
struct l_queue *test_stat_queue;
char **test_config_dirs;
sprintf(env_path, "%s/src:%s/tools:%s", top_level_path, top_level_path,
getenv("PATH"));
env_path = l_strdup_printf("%s/src:%s/tools:%s", top_level_path,
top_level_path, getenv("PATH"));
setenv("PATH", env_path, true);
sprintf(test_home_path, "%s/%s", top_level_path,
test_home_path = l_strdup_printf("%s/%s", top_level_path,
TEST_TOP_DIR_DEFAULT_NAME);
if (!path_exist(test_home_path)) {