From: Chet Ramey Date: Tue, 2 Dec 2025 22:15:44 +0000 (-0500) Subject: fix longjmp error when timing null command in posix mode; unset exit trap in subshell... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5a104e96d869e2bbf0f7f364f45d21e6fc151721;p=thirdparty%2Fbash.git fix longjmp error when timing null command in posix mode; unset exit trap in subshells before checking for pending fatal signal; changes for gcc sometimes-uninitialized warning --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 8580314b..65f4c95b 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -12282,3 +12282,32 @@ subst.c when they are expanded in a context that will not perform word splitting Report by Emanuele Torre + +execute_cmd.c + - time_command: make sure to initialize CODE in the posix and null + command case so we don't longjmp to nowhere + Report and patch from Grisha Levit + +pathexp.c + - globsort_sortarray: if the sort type is unknown, default sortfunc + to globsort_namecmp + +error.h + - programming_error: add `noreturn' attribute + + 11/25 + ----- +variables.c + - get_bash_name: use sh_realpath instead of sh_canonpath; less code + Modification of change from 11/18 + + 12/1 + ---- +trap.c, trap.h + - clear_exit_trap: new function to unset the exit trap and clear out + the trap string + +execute_cmd.c + - execute_in_subshell: clear the exit trap before checking for a + pending fatal signal + From https://savannah.gnu.org/bugs/?67745 diff --git a/builtins/printf.def b/builtins/printf.def index 2de73b54..2bb70581 100644 --- a/builtins/printf.def +++ b/builtins/printf.def @@ -176,6 +176,7 @@ extern int errno; #define SKIP1 "#'-+ 0" #define LENMODS "hjlLtz" +#define DIGITS "0123456789" #ifndef TIMELEN_MAX # define TIMELEN_MAX 128 @@ -246,7 +247,6 @@ static size_t vblen; static char **narg_argv; static int narg_argc; static int narg_maxind; -static int narg_curind; static intmax_t tw; diff --git a/doc/bashref.texi b/doc/bashref.texi index 7012cf6c..705d259b 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -9068,7 +9068,7 @@ The character whose ASCII code is the octal value @var{nnn}. A backslash. @item \[ Begin a sequence of non-printing characters. -Thiss could be used to +This could be used to embed a terminal control sequence into the prompt. @item \] End a sequence of non-printing characters. diff --git a/error.h b/error.h index db0972bc..6254fee1 100644 --- a/error.h +++ b/error.h @@ -30,7 +30,7 @@ extern char *get_name_for_error (void); extern void file_error (const char *); /* Report a programmer's error, and abort. Pass REASON, and ARG1 ... ARG5. */ -extern void programming_error (const char *, ...) __attribute__((__format__ (printf, 1, 2))); +extern void programming_error (const char *, ...) __attribute__((__format__ (printf, 1, 2))) __attribute__((__noreturn__));; /* General error reporting. Pass FORMAT and ARG1 ... ARG5. */ extern void report_error (const char *, ...) __attribute__((__format__ (printf, 1, 2))); diff --git a/execute_cmd.c b/execute_cmd.c index a0b66015..a6d4a096 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -1489,6 +1489,8 @@ time_command (COMMAND *command, int asynchronous, int pipe_in, int pipe_out, str rsf = usf = ssf = 0; cpu = 0; + code = 0; + old_subshell = subshell_environment; posix_time = command && (command->flags & CMD_TIME_POSIX); nullcmd = (command == 0) || (command->type == cm_simple && command->value.Simple->words == 0 && command->value.Simple->redirects == 0); @@ -1686,6 +1688,9 @@ execute_in_subshell (COMMAND *command, int asynchronous, int pipe_in, int pipe_o subshell_environment |= SUBSHELL_COPROC; } + /* clear the exit trap before checking for fatal signals */ + clear_exit_trap (); + QUIT; CHECK_TERMSIG; diff --git a/jobs.c b/jobs.c index 07f8ca7a..d8f7aae4 100644 --- a/jobs.c +++ b/jobs.c @@ -2317,7 +2317,7 @@ make_child (char *command, int flags) break; forksleep <<= 1; - if (interrupt_state) + if (interrupt_state) /* XXX - and terminating_signal? */ break; sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL); } diff --git a/pathexp.c b/pathexp.c index 1692e054..87c49bf3 100644 --- a/pathexp.c +++ b/pathexp.c @@ -904,6 +904,7 @@ globsort_sortarray (struct globsort_t *garray, size_t len) break; default: internal_error (_("invalid glob sort type")); + sortfunc = (QSFUNC *)globsort_namecmp; break; } diff --git a/trap.c b/trap.c index ea103f58..edac5540 100644 --- a/trap.c +++ b/trap.c @@ -1,7 +1,7 @@ /* trap.c -- Not the trap command, but useful functions for manipulating those objects. The trap command is in builtins/trap.def. */ -/* Copyright (C) 1987-2024 Free Software Foundation, Inc. +/* Copyright (C) 1987-2025 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -1102,6 +1102,18 @@ run_trap_cleanup (int sig) sigmodes[sig] &= ~(SIG_INPROGRESS|SIG_CHANGED); } +void +clear_exit_trap () +{ + if (sigmodes[EXIT_TRAP] & SIG_TRAPPED) + { + sigmodes[EXIT_TRAP] &= ~SIG_TRAPPED; /* XXX - SIG_INPROGRESS? */ + free_trap_command (EXIT_TRAP); + trap_list[EXIT_TRAP] = (char *)NULL; + } + +} + #define RECURSIVE_SIG(s) (SPECIAL_TRAP(s) == 0) /* Run a trap command for SIG. SIG is one of the signals the shell treats diff --git a/trap.h b/trap.h index 82a3c651..093beab2 100644 --- a/trap.h +++ b/trap.h @@ -1,6 +1,6 @@ /* trap.h -- data structures used in the trap mechanism. */ -/* Copyright (C) 1993-2023 Free Software Foundation, Inc. +/* Copyright (C) 1993-2025 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -91,6 +91,8 @@ extern void set_signal (int, const char *); extern void restore_default_signal (int); extern void ignore_signal (int); + +extern void clear_exit_trap (void); extern int run_exit_trap (void); extern void run_trap_cleanup (int); extern int run_debug_trap (void); diff --git a/variables.c b/variables.c index 00a73da8..5ef53a92 100644 --- a/variables.c +++ b/variables.c @@ -820,24 +820,11 @@ get_bash_name (void) tname = make_absolute (shell_name, get_string_value ("PWD")); if (*shell_name == '.') { - char *x, *fp; - - x = strrchr (tname, '/'); - *x = 0; - name = sh_canonpath (tname, PATH_CHECKDOTDOT|PATH_CHECKEXISTS); - *x++ = '/'; + name = sh_realpath (tname, 0); if (name == 0) name = tname; else - { - fp = sh_makepath (name, x, 0); - free (tname); - if (fp) - { - free (name); - name = fp; - } - } + free (tname); } else name = tname;