abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 42bb83bbb69bf57b4bf7d525fc89ad14fbe20d04
parent 62d31e784caad11403f01fb617e80fe3f0c17b5f
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sat,  9 Jan 2016 11:35:22 +0100

Change default command handling to not use out of scope variable

Should fix CID 121406.

Diffstat:
abduco.c | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/abduco.c b/abduco.c @@ -573,6 +573,13 @@ int main(int argc, char *argv[]) { int opt; bool force = false; char **cmd = NULL, action = '\0'; + + char *default_cmd[4] = { "/bin/sh", "-c", getenv("ABDUCO_CMD"), NULL }; + if (!default_cmd[2]) { + default_cmd[0] = "dvtm"; + default_cmd[1] = NULL; + } + server.name = basename(argv[0]); gethostname(server.host+1, sizeof(server.host) - 1); @@ -615,14 +622,8 @@ int main(int argc, char *argv[]) { /* if yet more trailing arguments, they must be the command */ if (optind + 1 < argc) cmd = &argv[optind + 1]; - - if (!cmd) { - char *default_cmd = getenv("ABDUCO_CMD"); - if (default_cmd) - cmd = (char*[]){ "/bin/sh", "-c", default_cmd, NULL }; - else - cmd = (char*[]){ "dvtm", NULL }; - } + else + cmd = default_cmd; if (!action && !server.session_name) exit(list_session());