[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] fix read uninitialized at exec_builtin:orig_job_control

From: Xiami
Subject: [PATCH] fix read uninitialized at exec_builtin:orig_job_control
Date: Wed, 17 Aug 2022 01:58:11 +0800

The following script will likely failed to echo "Failed to exec" in 
non-interactive mode:
    #ls -l /proc/$$/fd
    shopt -s execfail
    exec notexistexecutable
    echo >&2 "Failed to exec"
    #ls -l /proc/$$/fd

exec_builtin will `goto failed_exec` after `search_for_command(args[0], 1)`
returns NULL, before `orig_job_control = job_control`, causing read
uninitialized orig_job_control in failed_exec code.

Then in restart_job_control() (passed `if (orig_job_control)` check),
`close(shell_tty)` is called with shell_tty = 2 in non-interactive mode
(no job control), causing stderr to be closed.

Signed-off-by: Xiami <i@f2light.com>
 builtins/exec.def | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtins/exec.def b/builtins/exec.def
index cbcb641a..fb78614b 100644
--- a/builtins/exec.def
+++ b/builtins/exec.def
@@ -101,7 +101,7 @@ exec_builtin (list)
      WORD_LIST *list;
   int exit_value = EXECUTION_FAILURE;
-  int cleanenv, login, opt, orig_job_control;
+  int cleanenv, login, opt, orig_job_control = 0;
   char *argv0, *command, **args, **env, *newname, *com2;

   cleanenv = login = 0;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]