From 822ae765435824650ae8fe6f538489d1090c044f Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Thu, 6 Dec 2012 13:43:31 +0100 Subject: [PATCH] core: fix crash in child process of hook_process_hashtable when arguments are given in hashtable and that execvp() failed --- src/core/wee-hook.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index ffe96864e..5dd62f98d 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -1414,7 +1414,7 @@ void hook_process_child (struct t_hook *hook_process) { char **exec_args, str_arg[64]; - const char *ptr_url; + const char *ptr_url, *ptr_arg; int rc, i, num_args; /* @@ -1464,7 +1464,9 @@ hook_process_child (struct t_hook *hook_process) while (1) { snprintf (str_arg, sizeof (str_arg), "arg%d", num_args + 1); - if (!hashtable_has_key (HOOK_PROCESS(hook_process, options), str_arg)) + ptr_arg = hashtable_get (HOOK_PROCESS(hook_process, options), + str_arg); + if (!ptr_arg) break; num_args++; } @@ -1479,12 +1481,13 @@ hook_process_child (struct t_hook *hook_process) exec_args = malloc ((num_args + 2) * sizeof (exec_args[0])); if (exec_args) { - exec_args[0] = HOOK_PROCESS(hook_process, command); + exec_args[0] = strdup (HOOK_PROCESS(hook_process, command)); for (i = 1; i <= num_args; i++) { snprintf (str_arg, sizeof (str_arg), "arg%d", i); - exec_args[i] = (char *)hashtable_get (HOOK_PROCESS(hook_process, options), - str_arg); + ptr_arg = hashtable_get (HOOK_PROCESS(hook_process, options), + str_arg); + exec_args[i] = (ptr_arg) ? strdup (ptr_arg) : NULL; } exec_args[num_args + 1] = NULL; }