fix(p5-rsh): NULL-check argv tail str_dups in ssh_build_client_argv
This commit is contained in:
@@ -189,18 +189,40 @@ char** ssh_build_client_argv(const char* rsh_command, int port, const char* user
|
|||||||
char* tail[] = {"-o", "Compression=no",
|
char* tail[] = {"-o", "Compression=no",
|
||||||
"-o", "ControlMaster=auto",
|
"-o", "ControlMaster=auto",
|
||||||
"-o", "ControlPath=~/.cache/fastsync-%r@%h:%p"};
|
"-o", "ControlPath=~/.cache/fastsync-%r@%h:%p"};
|
||||||
for (size_t i = 0; i < sizeof(tail) / sizeof(tail[0]); i++)
|
for (size_t i = 0; i < sizeof(tail) / sizeof(tail[0]); i++) {
|
||||||
argv[ac++] = str_dup(tail[i]);
|
argv[ac] = str_dup(tail[i]);
|
||||||
|
if (!argv[ac])
|
||||||
|
goto fail_argv;
|
||||||
|
ac++;
|
||||||
|
}
|
||||||
if (port_extra) {
|
if (port_extra) {
|
||||||
char port_str[16];
|
char port_str[16];
|
||||||
snprintf(port_str, sizeof(port_str), "%d", port);
|
snprintf(port_str, sizeof(port_str), "%d", port);
|
||||||
argv[ac++] = str_dup("-p");
|
argv[ac] = str_dup("-p");
|
||||||
argv[ac++] = str_dup(port_str);
|
if (!argv[ac])
|
||||||
|
goto fail_argv;
|
||||||
|
ac++;
|
||||||
|
argv[ac] = str_dup(port_str);
|
||||||
|
if (!argv[ac])
|
||||||
|
goto fail_argv;
|
||||||
|
ac++;
|
||||||
}
|
}
|
||||||
argv[ac++] = str_dup(userhost);
|
argv[ac] = str_dup(userhost);
|
||||||
argv[ac++] = str_dup(remote_command);
|
if (!argv[ac])
|
||||||
|
goto fail_argv;
|
||||||
|
ac++;
|
||||||
|
argv[ac] = str_dup(remote_command);
|
||||||
|
if (!argv[ac])
|
||||||
|
goto fail_argv;
|
||||||
|
ac++;
|
||||||
argv[ac] = NULL;
|
argv[ac] = NULL;
|
||||||
return argv;
|
return argv;
|
||||||
|
|
||||||
|
fail_argv:
|
||||||
|
for (int i = 0; i < ac; i++)
|
||||||
|
free(argv[i]);
|
||||||
|
free(argv);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssh_free_client_argv(char** argv) {
|
void ssh_free_client_argv(char** argv) {
|
||||||
|
|||||||
Reference in New Issue
Block a user