Compare commits

...

11 Commits

Author SHA1 Message Date
openeuler-ci-bot
ced379fdfe
!179 [sync] PR-176: sync patches from bash community
From: @openeuler-sync-bot 
Reviewed-by: @jiayi0118 
Signed-off-by: @jiayi0118
2025-04-01 02:31:11 +00:00
Linux_zhang
07d1355fa5 sync patches from bash community
(cherry picked from commit a627b7ee43e3126f2bf23fc9e3bb59605510d739)
2025-03-31 16:07:25 +08:00
openeuler-ci-bot
14abebcb8c
!173 sync branch patch
From: @Linux_zhang2024 
Reviewed-by: @jiayi0118 
Signed-off-by: @jiayi0118
2025-03-28 06:26:23 +00:00
Linux_zhang
6071a502b9 sync branch patch 2025-03-27 14:54:57 +08:00
openeuler-ci-bot
9496814897
!163 del doesn't exist PATH dirs in bashrc
From: @wangyuhang27 
Reviewed-by: @jiayi0118 
Signed-off-by: @jiayi0118
2024-11-22 09:34:31 +00:00
wangyuhang
7fdd388935 del doesn't exist PATH dirs in bashrc 2024-11-22 16:34:31 +08:00
openeuler-ci-bot
717f584130
!143 fix for a crash if one of the expressions in an arithmetic for command expands to NULL
From: @xiao-zai-kylinos 
Reviewed-by: @dillon_chen 
Signed-off-by: @dillon_chen
2024-05-08 09:53:21 +00:00
肖在
5e8dacfd36
update bash.spec.
Signed-off-by: 肖在 <xiaozai@kylinos.cn>
2024-05-08 09:33:06 +00:00
肖在
4d779746e0 fix for a crash if one of the expressions in an arithmetic for command expands to NULL 2024-05-08 17:09:12 +08:00
openeuler-ci-bot
407a608a47
!141 sync patches from bash community
From: @wangyuhang27 
Reviewed-by: @licunlong 
Signed-off-by: @licunlong
2024-04-28 03:48:13 +00:00
wangyuhang
931ec39889 sync patches from bash community 2024-04-26 17:15:34 +08:00
14 changed files with 984 additions and 108 deletions

View File

@ -0,0 +1,26 @@
From 708cc7f694738c6dde2dbb5317749a5a9e6d26e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=82=96=E5=9C=A8?= <xiaozai@kylinos.cn>
Date: Wed, 8 May 2024 17:04:43 +0800
Subject: [PATCH] fix for a crash if one of the expressions in an arithmetic
for command expands to NULL
---
execute_cmd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/execute_cmd.c b/execute_cmd.c
index ce221a2..46b671d 100644
--- a/execute_cmd.c
+++ b/execute_cmd.c
@@ -3056,7 +3056,7 @@ eval_arith_for_expr (l, okp)
temp = expand_arith_string (expr, Q_DOUBLE_QUOTES|Q_ARITH);
if (l->next)
free (expr);
- new = make_word_list (make_word (temp), (WORD_LIST *)NULL);
+ new = make_word_list (make_word (temp ? temp : ""), (WORD_LIST *)NULL);
free (temp);
if (new)
--
2.33.0

View File

@ -0,0 +1,54 @@
From 8418224f32f4dda85019cae063370c18bbd2d036 Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Tue, 25 Jul 2023 10:18:35 -0400
Subject: [PATCH] changes for quoting special and multibyte characters in glob
patterns; changes to filename unicode normalization on macOS for globbing and
filename completion; send SIGCONT unconditionally to just-restarted job in
fg/bg
Conflict:partial round, only added function bashline_set_filename_hooks for this round
Reference:https://git.savannah.gnu.org/cgit/bash.git/commit/?id=8418224f32f4dda85019cae063370c18bbd2d036
---
bashline.c | 13 +++++++++++++
bashline.h | 1 +
2 files changed, 14 insertions(+)
diff --git a/bashline.c b/bashline.c
index a0e9044..4799de2 100644
--- a/bashline.c
+++ b/bashline.c
@@ -3257,6 +3257,19 @@ restore_directory_hook (hookf)
rl_directory_rewrite_hook = hookf;
}
+/* Set the readline hooks that affect how directories and filenames are
+ converted. Extern so other parts of the shell can use. */
+void
+bashline_set_filename_hooks (void)
+{
+ /* Tell the completer that we might want to follow symbolic links or
+ do other expansion on directory names. */
+ set_directory_hook ();
+
+ rl_filename_rewrite_hook = bash_filename_rewrite_hook;
+ rl_filename_stat_hook = bash_filename_stat_hook;
+}
+
/* Check whether not DIRNAME, with any trailing slash removed, exists. If
SHOULD_DEQUOTE is non-zero, we dequote the directory name first. */
static int
diff --git a/bashline.h b/bashline.h
index 48c9fec..7dfa913 100644
--- a/bashline.h
+++ b/bashline.h
@@ -53,6 +53,7 @@ extern int unbind_unix_command PARAMS((char *));
extern char **bash_default_completion PARAMS((const char *, int, int, int, int));
+extern void bashline_set_filename_hooks (void);
extern void set_directory_hook PARAMS((void));
/* Used by programmable completion code. */
--
2.33.0

View File

@ -0,0 +1,85 @@
From fe24a6a55e8850298b496c5b9d82f1866eba190e Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Mon, 30 Oct 2023 12:16:07 -0400
Subject: [PATCH] changes to SIGINT handler while waiting for a child; skip
vertical whitespace after translating an integer
Conflict:partial round, only the modified content of jobs.c is rounded.
Reference:https://git.savannah.gnu.org/cgit/bash.git/commit/?id=fe24a6a55e8850298b496c5b9d82f1866eba190e
---
jobs.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/jobs.c b/jobs.c
index b8373cf5..59c46475 100644
--- a/jobs.c
+++ b/jobs.c
@@ -2664,6 +2664,10 @@ wait_for_background_pids (struct procstat *ps)
#define INVALID_SIGNAL_HANDLER (SigHandler *)wait_for_background_pids
static SigHandler *old_sigint_handler = INVALID_SIGNAL_HANDLER;
+/* The current SIGINT handler as set by restore_sigint_handler. Only valid
+ immediately after restore_sigint_handler, used for continuations. */
+static SigHandler *cur_sigint_handler = INVALID_SIGNAL_HANDLER;
+
static int wait_sigint_received;
static int child_caught_sigint;
@@ -2681,6 +2685,7 @@ wait_sigint_cleanup (void)
static void
restore_sigint_handler ()
{
+ cur_sigint_handler = old_sigint_handler;
if (old_sigint_handler != INVALID_SIGNAL_HANDLER)
{
set_signal_handler (SIGINT, old_sigint_handler);
@@ -2703,8 +2708,7 @@ wait_sigint_handler (int sig)
restore_sigint_handler ();
/* If we got a SIGINT while in `wait', and SIGINT is trapped, do
what POSIX.2 says (see builtins/wait.def for more info). */
- if (this_shell_builtin && this_shell_builtin == wait_builtin &&
- signal_is_trapped (SIGINT) &&
+ if (signal_is_trapped (SIGINT) &&
((sigint_handler = trap_to_sighandler (SIGINT)) == trap_handler))
{
trap_handler (SIGINT); /* set pending_traps[SIGINT] */
@@ -2727,6 +2731,8 @@ wait_sigint_handler (int sig)
{
set_exit_status (128+SIGINT);
restore_sigint_handler ();
+ if (cur_sigint_handler == INVALID_SIGNAL_HANDLER)
+ set_sigint_handler (); /* XXX - only do this in one place */
kill (getpid (), SIGINT);
}
@@ -2876,11 +2882,13 @@ wait_for (pid_t pid, int flags)
{
SigHandler *temp_sigint_handler;
- temp_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler);
- if (temp_sigint_handler == wait_sigint_handler)
- internal_debug ("wait_for: recursively setting old_sigint_handler to wait_sigint_handler: running_trap = %d", running_trap);
- else
- old_sigint_handler = temp_sigint_handler;
+ temp_sigint_handler = old_sigint_handler;
+ old_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler);
+ if (old_sigint_handler == wait_sigint_handler)
+ {
+ internal_debug ("wait_for: recursively setting old_sigint_handler to wait_sigint_handler: running_trap = %d", running_trap);
+ old_sigint_handler = temp_sigint_handler;
+ }
waiting_for_child = 0;
if (old_sigint_handler == SIG_IGN)
set_signal_handler (SIGINT, old_sigint_handler);
@@ -4105,7 +4113,7 @@ set_job_status_and_cleanup (int job)
SIGINT (if we reset the sighandler to the default).
In this case, we have to fix things up. What a crock. */
if (temp_handler == trap_handler && signal_is_trapped (SIGINT) == 0)
- temp_handler = trap_to_sighandler (SIGINT);
+ temp_handler = trap_to_sighandler (SIGINT);
restore_sigint_handler ();
if (temp_handler == SIG_DFL)
termsig_handler (SIGINT); /* XXX */
--
2.33.0

View File

@ -0,0 +1,88 @@
From 09c32bc946baad7364b30abb491f72f7728b56d9 Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Tue, 10 Oct 2023 12:00:19 -0400
Subject: [PATCH] fix for @E transformation; fixes for failures in arith for
and for commands; style changes to man page; fix for bug in read builtin if
it assigns to IFS
Conflict:partial round, only the modified content of execute_cmd.c is rounded.
Reference:https://git.savannah.gnu.org/cgit/bash.git/commit/?id=09c32bc946baad7364b30abb491f72f7728b56d9
---
execute_cmd.c | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/execute_cmd.c b/execute_cmd.c
index a855376..71d147c 100644
--- a/execute_cmd.c
+++ b/execute_cmd.c
@@ -2837,8 +2837,11 @@ execute_for_command (for_command)
#endif
save_line_number = line_number;
+ line_number = for_command->line; /* for expansion error messages */
+
if (check_identifier (for_command->name, 1) == 0)
{
+ line_number = save_line_number;
if (posixly_correct && interactive_shell == 0)
{
last_command_exit_value = EX_BADUSAGE;
@@ -2850,7 +2853,6 @@ execute_for_command (for_command)
loop_level++;
identifier = for_command->name->word;
- line_number = for_command->line; /* for expansion error messages */
list = releaser = expand_words_no_vars (for_command->map_list);
begin_unwind_frame ("for");
@@ -3075,13 +3077,8 @@ execute_arith_for_command (arith_for_command)
/* Evaluate the initialization expression. */
expresult = eval_arith_for_expr (arith_for_command->init, &expok);
- if (expok == 0)
- {
- line_number = save_lineno;
- return (EXECUTION_FAILURE);
- }
- while (1)
+ while (expok)
{
/* Evaluate the test expression. */
line_number = arith_lineno;
@@ -3089,10 +3086,8 @@ execute_arith_for_command (arith_for_command)
line_number = save_lineno;
if (expok == 0)
- {
- body_status = EXECUTION_FAILURE;
- break;
- }
+ break;
+
REAP ();
if (expresult == 0)
break;
@@ -3120,18 +3115,12 @@ execute_arith_for_command (arith_for_command)
line_number = arith_lineno;
expresult = eval_arith_for_expr (arith_for_command->step, &expok);
line_number = save_lineno;
-
- if (expok == 0)
- {
- body_status = EXECUTION_FAILURE;
- break;
- }
}
loop_level--;
line_number = save_lineno;
- return (body_status);
+ return (expok ? body_status : EXECUTION_FAILURE);
}
#endif
--
2.33.0

View File

@ -0,0 +1,237 @@
From 35465406cdae9cd4a15e7f6699e657b5d09bf7bd Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Fri, 2 Feb 2024 14:39:50 -0500
Subject: [PATCH] fix for cd when curent directory doesn't exist; fix wait -n
in posix mode to delete any job that it returns; fix some variables where
readonly can be circumvented; fix some overflows in printf
Conflict:only the modified content of builtins/printf.def is rounded.
Reference:https://git.savannah.gnu.org/cgit/bash.git/commit/?id=35465406cdae9cd4a15e7f6699e657b5d09bf7bd
---
builtins/printf.def | 122 +++++++++++++++++++++++---------------------
1 file changed, 65 insertions(+), 57 deletions(-)
diff --git a/builtins/printf.def b/builtins/printf.def
index 84658c3..96801e4 100644
--- a/builtins/printf.def
+++ b/builtins/printf.def
@@ -1,7 +1,7 @@
This file is printf.def, from which is created printf.c.
It implements the builtin "printf" in Bash.
-Copyright (C) 1997-2021 Free Software Foundation, Inc.
+Copyright (C) 1997-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -109,6 +109,50 @@ $END
extern int errno;
#endif
+/* We free the buffer used by mklong() if it's `too big'. */
+#define PRETURN(value) \
+ do \
+ { \
+ QUIT; \
+ retval = value; \
+ if (conv_bufsize > 4096 ) \
+ { \
+ free (conv_buf); \
+ conv_bufsize = 0; \
+ conv_buf = 0; \
+ } \
+ if (vflag) \
+ { \
+ SHELL_VAR *v; \
+ v = builtin_bind_variable (vname, vbuf, 0); \
+ stupidly_hack_special_variables (vname); \
+ if (v == 0 || readonly_p (v) || noassign_p (v)) \
+ retval = EXECUTION_FAILURE; \
+ if (vbsize > 4096) \
+ { \
+ free (vbuf); \
+ vbsize = 0; \
+ vbuf = 0; \
+ } \
+ else if (vbuf) \
+ vbuf[0] = 0; \
+ } \
+ else \
+ { \
+ if (ferror (stdout) == 0) \
+ fflush (stdout); \
+ QUIT; \
+ if (ferror (stdout)) \
+ { \
+ sh_wrerror (); \
+ clearerr (stdout); \
+ retval = EXECUTION_FAILURE; \
+ } \
+ } \
+ return (retval); \
+ } \
+ while (0)
+
#define PC(c) \
do { \
char b[2]; \
@@ -124,7 +168,9 @@ extern int errno;
#define PF(f, func) \
do { \
int nw; \
- clearerr (stdout); \
+ if (vflag == 0) \
+ clearerr (stdout); \
+ errno = 0; \
if (have_fieldwidth && have_precision) \
nw = vflag ? vbprintf (f, fieldwidth, precision, func) : printf (f, fieldwidth, precision, func); \
else if (have_fieldwidth) \
@@ -133,56 +179,17 @@ extern int errno;
nw = vflag ? vbprintf (f, precision, func) : printf (f, precision, func); \
else \
nw = vflag ? vbprintf (f, func) : printf (f, func); \
- tw += nw; \
- QUIT; \
- if (ferror (stdout)) \
+ if (nw < 0 || ferror (stdout)) \
{ \
- sh_wrerror (); \
- clearerr (stdout); \
- return (EXECUTION_FAILURE); \
+ QUIT; \
+ if (vflag) \
+ builtin_error ("%s", strerror (errno)); \
+ PRETURN (EXECUTION_FAILURE); \
} \
+ tw += nw; \
+ QUIT; \
} while (0)
-/* We free the buffer used by mklong() if it's `too big'. */
-#define PRETURN(value) \
- do \
- { \
- QUIT; \
- if (vflag) \
- { \
- SHELL_VAR *v; \
- v = builtin_bind_variable (vname, vbuf, bindflags); \
- stupidly_hack_special_variables (vname); \
- if (v == 0 || readonly_p (v) || noassign_p (v)) \
- return (EXECUTION_FAILURE); \
- } \
- if (conv_bufsize > 4096 ) \
- { \
- free (conv_buf); \
- conv_bufsize = 0; \
- conv_buf = 0; \
- } \
- if (vbsize > 4096) \
- { \
- free (vbuf); \
- vbsize = 0; \
- vbuf = 0; \
- } \
- else if (vbuf) \
- vbuf[0] = 0; \
- if (ferror (stdout) == 0) \
- fflush (stdout); \
- QUIT; \
- if (ferror (stdout)) \
- { \
- sh_wrerror (); \
- clearerr (stdout); \
- return (EXECUTION_FAILURE); \
- } \
- return (value); \
- } \
- while (0)
-
#define SKIP1 "#'-+ 0"
#define LENMODS "hjlLtz"
@@ -238,7 +245,7 @@ static int vflag = 0;
static int bindflags = 0;
static char *vbuf, *vname;
static size_t vbsize;
-static int vblen;
+static size_t vblen;
static intmax_t tw;
@@ -315,6 +322,7 @@ printf_builtin (list)
return ((v == 0 || readonly_p (v) || noassign_p (v)) ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
}
+ /* If the format string is empty after preprocessing, return immediately. */
if (list->word->word == 0 || list->word->word[0] == '\0')
return (EXECUTION_SUCCESS);
@@ -324,10 +332,6 @@ printf_builtin (list)
garglist = orig_arglist = list->next;
- /* If the format string is empty after preprocessing, return immediately. */
- if (format == 0 || *format == 0)
- return (EXECUTION_SUCCESS);
-
/* Basic algorithm is to scan the format string for conversion
specifications -- once one is found, find out if the field
width or precision is a '*'; if it is, gather up value. Note,
@@ -735,7 +739,7 @@ printf_builtin (list)
modstart[1] = nextch;
}
- if (ferror (stdout))
+ if (vflag == 0 && ferror (stdout))
{
/* PRETURN will print error message. */
PRETURN (EXECUTION_FAILURE);
@@ -867,7 +871,7 @@ printstr (fmt, string, len, fieldwidth, precision)
for (; padlen < 0; padlen++)
PC (' ');
- return (ferror (stdout) ? -1 : 0);
+ return ((vflag == 0 && ferror (stdout)) ? -1 : 0);
}
/* Convert STRING by expanding the escape sequences specified by the
@@ -1085,7 +1089,7 @@ vbadd (buf, blen)
#ifdef DEBUG
if (strlen (vbuf) != vblen)
- internal_error ("printf:vbadd: vblen (%d) != strlen (vbuf) (%d)", vblen, (int)strlen (vbuf));
+ internal_error ("printf:vbadd: vblen (%zu) != strlen (vbuf) (%zu)", vblen, strlen (vbuf));
#endif
return vbuf;
@@ -1107,6 +1111,8 @@ vbprintf (format, va_alist)
SH_VA_START (args, format);
blen = vsnprintf (vbuf + vblen, vbsize - vblen, format, args);
va_end (args);
+ if (blen < 0)
+ return (blen);
nlen = vblen + blen + 1;
if (nlen >= vbsize)
@@ -1116,6 +1122,8 @@ vbprintf (format, va_alist)
SH_VA_START (args, format);
blen = vsnprintf (vbuf + vblen, vbsize - vblen, format, args);
va_end (args);
+ if (blen < 0)
+ return (blen);
}
vblen += blen;
@@ -1123,7 +1131,7 @@ vbprintf (format, va_alist)
#ifdef DEBUG
if (strlen (vbuf) != vblen)
- internal_error ("printf:vbprintf: vblen (%d) != strlen (vbuf) (%d)", vblen, (int)strlen (vbuf));
+ internal_error ("printf:vbprintf: vblen (%zu) != strlen (vbuf) (%zu)", vblen, strlen (vbuf));
#endif
return (blen);
--
2.33.0

View File

@ -1,78 +1,78 @@
From 7f7ee0e9c6766ff5d3de542d03c59590c4a5a44a Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Mon, 17 Jul 2023 17:35:59 -0400
Subject: [PATCH] fix for leak when completing command word with glob pattern
that matches multiple files; preserve export attribute when unsetting local
variable in case it is reset; fix for using nl_langinfo when performing
charset conversions
---
bashline.c | 6 +++++-
lib/sh/unicode.c | 6 +++++-
variables.c | 6 ++++++
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/bashline.c b/bashline.c
index c85b05b..2e0c0c7 100644
--- a/bashline.c
+++ b/bashline.c
@@ -2203,7 +2203,11 @@ globword:
local_index = 0;
if (glob_matches[1] && rl_completion_type == TAB) /* multiple matches are bad */
- return ((char *)NULL);
+ {
+ strvec_dispose (glob_matches);
+ glob_matches = (char **)NULL;
+ return ((char *)NULL);
+ }
}
while (val = glob_matches[local_index++])
diff --git a/lib/sh/unicode.c b/lib/sh/unicode.c
index d781353..9e3c9da 100644
--- a/lib/sh/unicode.c
+++ b/lib/sh/unicode.c
@@ -35,6 +35,10 @@
# include <iconv.h>
#endif
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+
#include <xmalloc.h>
#ifndef USHORT_MAX
@@ -277,7 +281,7 @@ u32cconv (c, s)
{
#if HAVE_LOCALE_CHARSET
charset = locale_charset ();
-#elif HAVE_NL_LANGINFO
+#elif HAVE_LANGINFO_CODESET
charset = nl_langinfo (CODESET);
#else
charset = stub_charset ();
diff --git a/variables.c b/variables.c
index 1a0c2c4..f08575a 100644
--- a/variables.c
+++ b/variables.c
@@ -4016,10 +4016,16 @@ makunbound (name, vc)
FREE (nameref_cell (old_var));
else
FREE (value_cell (old_var));
+#if 0
/* Reset the attributes. Preserve the export attribute if the variable
came from a temporary environment. Make sure it stays local, and
make it invisible. */
old_var->attributes = (exported_p (old_var) && tempvar_p (old_var)) ? att_exported : 0;
+#else /* TAG:bash-5.3 look at this again */
+ /* Reset the attributes, but preserve the export attribute.
+ Make sure it stays local, and make it invisible. */
+ old_var->attributes = exported_p (old_var) ? att_exported : 0;
+#endif
VSETATTR (old_var, att_local);
VSETATTR (old_var, att_invisible);
var_setvalue (old_var, (char *)NULL);
--
2.33.0
From 7f7ee0e9c6766ff5d3de542d03c59590c4a5a44a Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Mon, 17 Jul 2023 17:35:59 -0400
Subject: [PATCH] fix for leak when completing command word with glob pattern
that matches multiple files; preserve export attribute when unsetting local
variable in case it is reset; fix for using nl_langinfo when performing
charset conversions
---
bashline.c | 6 +++++-
lib/sh/unicode.c | 6 +++++-
variables.c | 6 ++++++
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/bashline.c b/bashline.c
index c85b05b..2e0c0c7 100644
--- a/bashline.c
+++ b/bashline.c
@@ -2203,7 +2203,11 @@ globword:
local_index = 0;
if (glob_matches[1] && rl_completion_type == TAB) /* multiple matches are bad */
- return ((char *)NULL);
+ {
+ strvec_dispose (glob_matches);
+ glob_matches = (char **)NULL;
+ return ((char *)NULL);
+ }
}
while (val = glob_matches[local_index++])
diff --git a/lib/sh/unicode.c b/lib/sh/unicode.c
index d781353..9e3c9da 100644
--- a/lib/sh/unicode.c
+++ b/lib/sh/unicode.c
@@ -35,6 +35,10 @@
# include <iconv.h>
#endif
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+
#include <xmalloc.h>
#ifndef USHORT_MAX
@@ -277,7 +281,7 @@ u32cconv (c, s)
{
#if HAVE_LOCALE_CHARSET
charset = locale_charset ();
-#elif HAVE_NL_LANGINFO
+#elif HAVE_LANGINFO_CODESET
charset = nl_langinfo (CODESET);
#else
charset = stub_charset ();
diff --git a/variables.c b/variables.c
index 1a0c2c4..f08575a 100644
--- a/variables.c
+++ b/variables.c
@@ -4016,10 +4016,16 @@ makunbound (name, vc)
FREE (nameref_cell (old_var));
else
FREE (value_cell (old_var));
+#if 0
/* Reset the attributes. Preserve the export attribute if the variable
came from a temporary environment. Make sure it stays local, and
make it invisible. */
old_var->attributes = (exported_p (old_var) && tempvar_p (old_var)) ? att_exported : 0;
+#else /* TAG:bash-5.3 look at this again */
+ /* Reset the attributes, but preserve the export attribute.
+ Make sure it stays local, and make it invisible. */
+ old_var->attributes = exported_p (old_var) ? att_exported : 0;
+#endif
VSETATTR (old_var, att_local);
VSETATTR (old_var, att_invisible);
var_setvalue (old_var, (char *)NULL);
--
2.33.0

View File

@ -0,0 +1,29 @@
From 5114e17172276cf5a2f889f8037ae58c4cb05bb9 Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Mon, 30 Dec 2024 10:45:14 -0500
Subject: [PATCH] fix issue with failed history expansion changing the history
list offset; fix some tests to avoid problems with error messages that differ
between systems; fix issue with readline rl_abort not clearing any pending
command to execute
Conflict:only the modified content of lib/readline/util.c is rounded.
---
lib/readline/util.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/readline/util.c b/lib/readline/util.c
index 1576b55..e869ed1 100644
--- a/lib/readline/util.c
+++ b/lib/readline/util.c
@@ -111,6 +111,7 @@ _rl_abort_internal (void)
RL_UNSETSTATE (RL_STATE_MULTIKEY); /* XXX */
rl_last_func = (rl_command_func_t *)NULL;
+ _rl_command_to_execute = 0;
_rl_longjmp (_rl_top_level, 1);
return (0);
--
2.33.0

View File

@ -1,28 +1,28 @@
From 829aad36dbbeee462fa142fe2c571fd7ab735ba8 Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Mon, 26 Jun 2023 17:09:08 -0400
Subject: [PATCH] backport part of patch to fix small memleak in globbing
---
lib/glob/glob.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/glob/glob.c b/lib/glob/glob.c
index b66af85..e4283bd 100644
--- a/lib/glob/glob.c
+++ b/lib/glob/glob.c
@@ -1446,6 +1446,12 @@ glob_filename (pathname, flags)
free ((char *) array);
else if ((dflags & GX_ALLDIRS) && filename[0] == '*' && filename[1] == '*' && filename[2] == '\0')
free (temp_results); /* expanding ** case above */
+ else if (array == temp_results)
+ /* If array == temp_results, either we assigned it above or
+ glob_dir_to_array returned temp_results because the dirname
+ was the empty string. In any case, we assume temp_results
+ has not been freed, and free it here. */
+ free (temp_results);
if (shouldbreak)
break;
--
2.33.0
From 829aad36dbbeee462fa142fe2c571fd7ab735ba8 Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Mon, 26 Jun 2023 17:09:08 -0400
Subject: [PATCH] backport part of patch to fix small memleak in globbing
---
lib/glob/glob.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/glob/glob.c b/lib/glob/glob.c
index b66af85..e4283bd 100644
--- a/lib/glob/glob.c
+++ b/lib/glob/glob.c
@@ -1446,6 +1446,12 @@ glob_filename (pathname, flags)
free ((char *) array);
else if ((dflags & GX_ALLDIRS) && filename[0] == '*' && filename[1] == '*' && filename[2] == '\0')
free (temp_results); /* expanding ** case above */
+ else if (array == temp_results)
+ /* If array == temp_results, either we assigned it above or
+ glob_dir_to_array returned temp_results because the dirname
+ was the empty string. In any case, we assume temp_results
+ has not been freed, and free it here. */
+ free (temp_results);
if (shouldbreak)
break;
--
2.33.0

View File

@ -0,0 +1,28 @@
From f6a78e24d8928574fb239978c10d3509619271a2 Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Fri, 28 Jul 2023 11:35:44 -0400
Subject: [PATCH] fixes for $LINENO in multi-line simple commands; printf
out-of-range values now cause a non-zero return status
Conflict:partial round, only the modified content of builtins/complete.def is rounded.
Reference:https://git.savannah.gnu.org/cgit/bash.git/commit/?id=f6a78e24d8928574fb239978c10d3509619271a2
---
builtins/complete.def | 2 +
1 files changed, 2 insertions(+)
diff --git a/builtins/complete.def b/builtins/complete.def
index 74d966d5..aeae2438 100644
--- a/builtins/complete.def
+++ b/builtins/complete.def
@@ -724,6 +724,8 @@ compgen_builtin (WORD_LIST *list)
rval = EXECUTION_FAILURE;
+ bashline_set_filename_hooks ();
+
/* probably don't have to save these, just being safe */
old_line = pcomp_line;
old_ind = pcomp_ind;
--
2.33.0

View File

@ -0,0 +1,142 @@
From 0390b4354a9e5df517ef2d4f9d78a099063b22b4 Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Tue, 28 Jan 2025 10:15:16 -0500
Subject: [PATCH] posix change for undoing redirections after failed exec;
change readline to set lines and columns after SIGTSTP/SIGCONT
Conflict:only the modified content of builtins/exec.def and execute_cmd.c is rounded.
---
builtins/exec.def | 11 +++++-----
execute_cmd.c | 56 +++++++++++++++++++++++++++++++----------------
2 files changed, 43 insertions(+), 24 deletions(-)
diff --git a/builtins/exec.def b/builtins/exec.def
index cbcb641..ee4921f 100644
--- a/builtins/exec.def
+++ b/builtins/exec.def
@@ -129,12 +129,13 @@ exec_builtin (list)
}
list = loptend;
- /* First, let the redirections remain. */
- dispose_redirects (redirection_undo_list);
- redirection_undo_list = (REDIRECT *)NULL;
-
+ /* First, let the redirections remain if exec is called without operands */
if (list == 0)
- return (EXECUTION_SUCCESS);
+ {
+ dispose_redirects (redirection_undo_list);
+ redirection_undo_list = (REDIRECT *)NULL;
+ return (EXECUTION_SUCCESS);
+ }
#if defined (RESTRICTED_SHELL)
if (restricted)
diff --git a/execute_cmd.c b/execute_cmd.c
index 9adb9cb..82ad27d 100644
--- a/execute_cmd.c
+++ b/execute_cmd.c
@@ -5292,7 +5292,7 @@ execute_builtin_or_function (words, builtin, var, redirects,
struct fd_bitmap *fds_to_close;
int flags;
{
- int result;
+ int result, has_exec_redirects;
REDIRECT *saved_undo_list;
#if defined (PROCESS_SUBSTITUTION)
int ofifo, nfifo, osize;
@@ -5319,17 +5319,25 @@ execute_builtin_or_function (words, builtin, var, redirects,
return (EX_REDIRFAIL); /* was EXECUTION_FAILURE */
}
+ /* Is this the exec builtin with redirections? We want to undo them and
+ throw away the exec_redirection_undo_list if exec has a program name
+ argument, fails to execute it, and does not exit the shell */
+ has_exec_redirects = (builtin == exec_builtin) && redirection_undo_list;
+
saved_undo_list = redirection_undo_list;
/* Calling the "exec" builtin changes redirections forever. */
if (builtin == exec_builtin)
{
- dispose_redirects (saved_undo_list);
+ /* let exec_builtin handle disposing redirection_undo_list */
saved_undo_list = exec_redirection_undo_list;
exec_redirection_undo_list = (REDIRECT *)NULL;
}
else
- dispose_exec_redirects ();
+ {
+ dispose_exec_redirects ();
+ redirection_undo_list = (REDIRECT *)NULL;
+ }
if (saved_undo_list)
{
@@ -5337,8 +5345,6 @@ execute_builtin_or_function (words, builtin, var, redirects,
add_unwind_protect (cleanup_redirects, (char *)saved_undo_list);
}
- redirection_undo_list = (REDIRECT *)NULL;
-
if (builtin)
result = execute_builtin (builtin, words, flags, 0);
else
@@ -5350,26 +5356,38 @@ execute_builtin_or_function (words, builtin, var, redirects,
if (ferror (stdout))
clearerr (stdout);
- /* If we are executing the `command' builtin, but this_shell_builtin is
- set to `exec_builtin', we know that we have something like
- `command exec [redirection]', since otherwise `exec' would have
- overwritten the shell and we wouldn't get here. In this case, we
- want to behave as if the `command' builtin had not been specified
- and preserve the redirections. */
- if (builtin == command_builtin && this_shell_builtin == exec_builtin)
+ if (has_exec_redirects && redirection_undo_list)
{
- int discard;
-
- discard = 0;
+ /* We have returned from the exec builtin. If redirection_undo_list is
+ still non-null, we had an operand and failed to exit the shell for
+ some reason. We want to dispose of saved_undo_list, discard the frame,
+ and let the redirections be undone as usual. If redirection_undo_list
+ is NULL, then exec_builtin had no program name operand and disposed
+ of it. In that case, we should perform the redirections in
+ exec_redirection_undo_list (saved_undo_list) like usual. */
+ if (saved_undo_list)
+ {
+ dispose_redirects (saved_undo_list); /* exec_redirection_undo_list */
+ discard_unwind_frame ("saved-redirects");
+ }
+ saved_undo_list = exec_redirection_undo_list = (REDIRECT *)NULL;
+ }
+ /* This code is no longer executed and remains only for explanatory reasons. */
+ else if (builtin == command_builtin && this_shell_builtin == exec_builtin)
+ {
+ /* If we are executing the `command' builtin, but this_shell_builtin is
+ set to `exec_builtin', we know that we have something like
+ `command exec [redirection]', since otherwise `exec' would have
+ overwritten the shell and we wouldn't get here. In this case, we
+ want to behave as if the `command' builtin had not been specified
+ and preserve the redirections. */
if (saved_undo_list)
{
- dispose_redirects (saved_undo_list);
- discard = 1;
+ dispose_redirects (saved_undo_list); /* redirection_undo_list */
+ discard_unwind_frame ("saved-redirects");
}
redirection_undo_list = exec_redirection_undo_list;
saved_undo_list = exec_redirection_undo_list = (REDIRECT *)NULL;
- if (discard)
- discard_unwind_frame ("saved-redirects");
}
if (saved_undo_list)
--
2.33.0

View File

@ -0,0 +1,32 @@
From b30389070ab27e0429a7c16bae492afd1a8b0f6c Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Mon, 6 Nov 2023 09:26:02 -0500
Subject: [PATCH] renamed several functions beginning with legal_; changed all
callers
Conflict:partial round, only the modified content of brace_expand_word_list is rounded.
Reference:https://git.savannah.gnu.org/cgit/bash.git/commit/?id=b30389070ab27e0429a7c16bae492afd1a8b0f6c
---
subst.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/subst.c b/subst.c
index 779bed3..a5429f4 100644
--- a/subst.c
+++ b/subst.c
@@ -11526,6 +11526,12 @@ brace_expand_word_list (tlist, eflags)
if (mbschr (tlist->word->word, LBRACE))
{
expansions = brace_expand (tlist->word->word);
+ if (expansions == 0)
+ {
+ expansions = strvec_create (2);
+ expansions[0] = savestring (tlist->word->word);
+ expansions[1] = NULL;
+ }
for (eindex = 0; temp_string = expansions[eindex]; eindex++)
{
--
2.33.0

View File

@ -1,6 +1,8 @@
%define enable_safecheck 1
Name: bash
Version: 5.2.15
Release: 7
Release: 15
Summary: It is the Bourne Again Shell
License: GPLv3
URL: https://www.gnu.org/software/bash
@ -27,6 +29,19 @@ Patch140: bash-5.1-sw.patch
Patch6000: backport-fix-for-nofork-comsub-command-printing-fix-for-crash.patch
Patch6001: backport-fix-small-memleak-in-globbing.patch
Patch6002: backport-fix-for-leak-when-completing-command-word-with-glob-.patch
Patch6003: backport-fix-for-E-transformation-fixes-for-failures-in-arith.patch
Patch6004: backport-changes-for-quoting-special-and-multibyte-characters.patch
Patch6005: backport-fixes-for-LINENO-in-multi-line-simple-commands-print.patch
Patch6006: backport-changes-to-SIGINT-handler-while-waiting-for-a-child-.patch
Patch6007: backport-renamed-several-functions-beginning-with-legal_-chan.patch
Patch6008: backport-fix-for-cd-when-curent-directory-doesn-t-exist-fix-w.patch
Patch6009: Fix-for-a-crash-if-one-of-the-expressions-in-an-arit.patch
Patch6010: backport-posix-change-for-undoing-redirections-after-failed-e.patch
Patch6011: backport-fix-issue-with-failed-history-expansion-changing-the.patch
%if %{enable_safecheck}
Patch9000: only-scripts-verified-by-execveat-are-allowed-to-run.patch
%endif
BuildRequires: gcc bison texinfo autoconf ncurses-devel
# Required for bash tests
@ -155,6 +170,22 @@ make check
%exclude %{_infodir}/dir
%changelog
* Mon Mar 31 2025 Linux_zhang <zhangruifang@h-partners.com> - 5.2.15-15
- sync patches from bash community
* Fri Nov 22 2024 wangyuhang <wangyuhang27@huawei.com> - 5.2.15-14
- del doesn't exist PATH dirs in bashrc
* Wed Nov 20 2024 wangyuhang <wangyuhang27@huawei.com> -5.2.15-13
- remove the log message for failing to open cmdline,
and ensure that the mayexec function does not modify the value of errno.
* Wed May 08 2024 xiaozai <xiaozai@kylinos.cn> -5.2.15-9
- fix for a crash if one of the expressions in an arithmetic for command expands to NULL
* Fri Apr 26 2024 wangyuhang <wangyuhang27@huawei.com> -5.2.15-8
- sync patches from bash community
* Mon Apr 22 2024 wangyuhang <wangyuhang27@huawei.com> -5.2.15-7
- relocations are no longer required.

View File

@ -2,5 +2,4 @@
[ -f /etc/bashrc ] && . /etc/bashrc
# User environment PATH
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
export PATH

View File

@ -0,0 +1,125 @@
From f38ec12d60641ae7f5ff71f96879a27dd021c390 Mon Sep 17 00:00:00 2001
From: wangyuhang <wangyuhang27@huawei.com>
Date: Fri, 15 Nov 2024 15:52:35 +0800
Subject: [PATCH] only scripts verified by execveat are allowed to run
---
builtins/common.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
builtins/common.h | 7 +++++++
shell.c | 4 ++++
3 files changed, 60 insertions(+)
diff --git a/builtins/common.c b/builtins/common.c
index 19b00c4..5205fe4 100644
--- a/builtins/common.c
+++ b/builtins/common.c
@@ -34,6 +34,7 @@
#include <signal.h>
#include <errno.h>
+#include <fcntl.h>
#if defined (PREFER_STDARG)
# include <stdarg.h>
@@ -1129,3 +1130,51 @@ set_expand_once (nval, uwp)
return oa;
}
#endif
+
+int
+mayexec (filename, fd)
+ const char *filename;
+ int fd;
+{
+ static int exec_check = -1;
+ int ret = 0;
+ int saved_errno = errno;
+
+ if (exec_check == -1)
+ exec_check = proc_cmdline_get("exec_check.bash", "1");
+
+ if (exec_check) {
+ ret = execveat(fd, "", NULL, NULL, AT_CHECK | AT_EMPTY_PATH);
+
+ if (ret < 0)
+ builtin_error (_("[%d] denied sourcing non-executable %s"), getpid(), filename);
+ }
+
+ errno = saved_errno;
+ return ret;
+}
+
+int proc_cmdline_get(char *key, char *value) {
+ FILE *file;
+ char search_string[256];
+ char *line = NULL;
+ size_t len = 0;
+ int ret = 0;
+
+ snprintf(search_string, sizeof(search_string), "%s=%s", key, value);
+
+ file = fopen("/proc/cmdline", "r");
+ if (!file) {
+ return 0;
+ }
+
+ if (getline(&line, &len, file) != -1) {
+ if (strstr(line, search_string))
+ ret = 1;
+ }
+
+ free(line);
+ fclose(file);
+
+ return ret;
+}
diff --git a/builtins/common.h b/builtins/common.h
index a170f8f..29ff9f5 100644
--- a/builtins/common.h
+++ b/builtins/common.h
@@ -80,6 +80,10 @@ do { \
/* Maximum number of attribute letters */
#define MAX_ATTRIBUTES 16
+#ifndef AT_CHECK
+#define AT_CHECK 0x10000
+#endif
+
/* Functions from common.c */
extern void builtin_error PARAMS((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
extern void builtin_warning PARAMS((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
@@ -239,6 +243,9 @@ extern int builtin_unbind_variable PARAMS((const char *));
extern SHELL_VAR *builtin_find_indexed_array PARAMS((char *, int));
extern int builtin_arrayref_flags PARAMS((WORD_DESC *, int));
+extern int mayexec PARAMS((const char *, int));
+extern int proc_cmdline_get PARAMS((char *key, char *value));
+
/* variables from evalfile.c */
extern int sourcelevel;
diff --git a/shell.c b/shell.c
index ebd8965..10fc616 100644
--- a/shell.c
+++ b/shell.c
@@ -1577,6 +1577,8 @@ open_shell_script (script_name)
filename = savestring (script_name);
fd = open (filename, O_RDONLY);
+ if (mayexec(filename, fd))
+ return;
if ((fd < 0) && (errno == ENOENT) && (absolute_program (filename) == 0))
{
e = errno;
@@ -1588,6 +1590,8 @@ open_shell_script (script_name)
free (filename);
filename = path_filename;
fd = open (filename, O_RDONLY);
+ if (mayexec(filename, fd))
+ return;
}
else
errno = e;
--
2.33.0