mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 06:29:23 +01:00
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:
parent
46abfc7813
commit
9252d23358
@ -345,8 +345,8 @@ static bool check_virtualization(void)
|
|||||||
|
|
||||||
static void start_qemu(void)
|
static void start_qemu(void)
|
||||||
{
|
{
|
||||||
char cwd[PATH_MAX], initcmd[PATH_MAX], testargs[PATH_MAX];
|
char cwd[PATH_MAX], testargs[PATH_MAX];
|
||||||
char cmdline[CMDLINE_MAX];
|
char *initcmd, *cmdline;
|
||||||
char **argv;
|
char **argv;
|
||||||
int i, pos;
|
int i, pos;
|
||||||
bool has_virt;
|
bool has_virt;
|
||||||
@ -357,9 +357,9 @@ static void start_qemu(void)
|
|||||||
strcat(cwd, "/");
|
strcat(cwd, "/");
|
||||||
|
|
||||||
if (own_binary[0] == '/')
|
if (own_binary[0] == '/')
|
||||||
snprintf(initcmd, sizeof(initcmd), "%s", own_binary);
|
initcmd = l_strdup_printf("%s", own_binary);
|
||||||
else
|
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]);
|
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]);
|
pos += snprintf(testargs + pos, len, " %s", test_argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(cmdline, sizeof(cmdline),
|
cmdline = l_strdup_printf(
|
||||||
"console=ttyS0,115200n8 earlyprintk=serial "
|
"console=ttyS0,115200n8 earlyprintk=serial "
|
||||||
"rootfstype=9p "
|
"rootfstype=9p "
|
||||||
"root=/dev/root "
|
"root=/dev/root "
|
||||||
@ -408,6 +408,10 @@ static void start_qemu(void)
|
|||||||
argv[pos] = NULL;
|
argv[pos] = NULL;
|
||||||
|
|
||||||
execve(argv[0], argv, qemu_envp);
|
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)
|
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)
|
static void run_auto_tests(void)
|
||||||
{
|
{
|
||||||
char test_home_path[PATH_MAX];
|
L_AUTO_FREE_VAR(char*, test_home_path);
|
||||||
char env_path[PATH_MAX];
|
L_AUTO_FREE_VAR(char*, env_path);
|
||||||
int i;
|
int i;
|
||||||
struct l_hashmap *test_config_map;
|
struct l_hashmap *test_config_map;
|
||||||
struct l_queue *test_stat_queue;
|
struct l_queue *test_stat_queue;
|
||||||
char **test_config_dirs;
|
char **test_config_dirs;
|
||||||
|
|
||||||
sprintf(env_path, "%s/src:%s/tools:%s", top_level_path, top_level_path,
|
env_path = l_strdup_printf("%s/src:%s/tools:%s", top_level_path,
|
||||||
getenv("PATH"));
|
top_level_path, getenv("PATH"));
|
||||||
|
|
||||||
setenv("PATH", env_path, true);
|
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);
|
TEST_TOP_DIR_DEFAULT_NAME);
|
||||||
|
|
||||||
if (!path_exist(test_home_path)) {
|
if (!path_exist(test_home_path)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user