From 42bb83bbb69bf57b4bf7d525fc89ad14fbe20d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 9 Jan 2016 11:35:22 +0100 Subject: [PATCH] Change default command handling to not use out of scope variable Should fix CID 121406. --- abduco.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/abduco.c b/abduco.c index f10b5c1..7a9012e 100644 --- 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());