fix for wait -n' in posix mode; fix for long messages in readline; fix for short reads by source' builtin; fix for crash on RISC-V machines; fix for bad memory read when getopts is called twice with different sets of arguments

This commit is contained in:
Chet Ramey
2025-07-18 11:53:01 -04:00
parent 80a8f650a1
commit 01070d4324
15 changed files with 289 additions and 410 deletions
+54
View File
@@ -11363,3 +11363,57 @@ subst.c
subscript, remove backslashes quoting `[', `]', and `~', since those
are quoted by expand_array_subscript but not dequoted anywhere else
Fixes quoting bug reported by Isabella Bosia <izaberina@gmail.com>
7/14
----
jobs.c
- wait_for_any_job: in posix mode, only look in the bgpids list if
JWAIT_WAITING isn't set in FLAGS, indicating that wait -n didn't
get any pid or job arguments
Fixes bug reported by John Sidles <jasidles@gmail.com>
lib/readline/display.c
- rl_message: reallocate msg_buf only if vsnprintf returns a count
greater than msg_bufsiz - 1, and allow vsnprintf to write a full
msg_bufsiz bytes, since the count it returns includes the
trailing NULL.
Report and fix from Torgny Lyon <torgny@abc.se>
7/15
----
builtins/evalfile.c
- evalfile_internal: if we get a short read, less than the file size
as reported by the kernel, don't treat it as an error
Report from Emanuele Torre <torreemanuele6@gmail.com>
doc/bash.1,lib/readline/doc/readline.3,lib/readline/doc/rluser.texi
- bind-tty-special-chars: clarify that the bindings take place on
each call to readline()
7/16
----
command.h
- make sure the first few members of a COMMAND and a SIMPLE_COM are
aligned so casts from the latter to the former work correctly on
systems with fat pointers.
From https://savannah.gnu.org/bugs/?67323
7/17
----
lib/sh/anonfile.c
- anonshmopen: remove shm_open code; just use shm_mkstemp if it's
available.
From https://savannah.gnu.org/bugs/index.php?67326
builtins/getopt.c
- sh_getopt_restore_state: make sure not to set `nextchar' beyond the
end of the current argument, in case someone called getopts twice
without resetting OPTIND.
Fixes asan bug reported by Nathan Mills <the.true.nathan.mills@gmail.com>
builtins/getopt.c,builtins/getopt.h
- sh_getopt_reset: small function to reset nextchar and sh_charindex
builtins/getopts.def
- dogetopts: call sh_getopt_reset when binding the name variable fails
for some reason
+2
View File
@@ -160,8 +160,10 @@ file_error_and_exit:
nr = read (fd, string, file_size);
if (nr >= 0)
string[nr] = '\0';
#if 0
if (nr != file_size)
nr = -1; /* XXX - didn't get the whole file */
#endif
}
else
nr = zmapfd (fd, &string, 0);
+15 -2
View File
@@ -215,8 +215,13 @@ sh_getopt (int argc, char *const *argv, const char *optstring)
void
sh_getopt_restore_state (char **argv)
{
size_t len;
if (nextchar && argv && argv[sh_curopt])
nextchar = argv[sh_curopt] + sh_charindex;
{
len = strlen (argv[sh_curopt]);
nextchar = (sh_charindex <= len) ? argv[sh_curopt] + sh_charindex : NULL;
}
}
sh_getopt_state_t *
@@ -274,7 +279,15 @@ sh_getopt_debug_restore_state (char **argv)
}
}
#endif
/* When we want to reset things on an error */
void
sh_getopt_reset (void)
{
nextchar = NULL;
sh_charindex = 0;
}
#ifdef TEST
/* Compile with -DTEST to make an executable for use in testing
+2
View File
@@ -79,4 +79,6 @@ extern void sh_getopt_dispose_istate (sh_getopt_state_t *);
extern sh_getopt_state_t *sh_getopt_save_istate (void);
extern void sh_getopt_restore_istate (sh_getopt_state_t *);
extern void sh_getopt_reset (void);
#endif /* _SH_GETOPT_H */
+4 -1
View File
@@ -302,7 +302,10 @@ dogetopts (int argc, char **argv)
strval[0] = (char) ret;
strval[1] = '\0';
return (getopts_bind_variable (name, strval));
ret = getopts_bind_variable (name, strval);
if (ret != EXECUTION_SUCCESS)
sh_getopt_reset ();
return ret;
}
/* The getopts builtin. Build an argv, and call dogetopts with it. */
+2 -2
View File
@@ -195,7 +195,6 @@ typedef struct element {
/* What a command looks like. */
typedef struct command {
enum command_type type; /* FOR CASE WHILE IF CONNECTION or SIMPLE. */
int flags; /* Flags controlling execution environment. */
int line; /* line number the command starts on */
REDIRECT *redirects; /* Special redirects for FOR CASE, etc. */
@@ -223,6 +222,7 @@ typedef struct command {
struct subshell_com *Subshell;
struct coproc_com *Coproc;
} value;
enum command_type type; /* FOR CASE WHILE IF CONNECTION SIMPLE, etc. */
} COMMAND;
/* Structure used to represent the CONNECTION type. */
@@ -337,9 +337,9 @@ typedef struct cond_com {
typedef struct simple_com {
int flags; /* See description of CMD flags. */
int line; /* line number the command starts on */
REDIRECT *redirects; /* Redirections to perform. */
WORD_LIST *words; /* The program name, the arguments,
variable assignments, etc. */
REDIRECT *redirects; /* Redirections to perform. */
} SIMPLE_COM;
/* The "function definition" command. */
+6 -2
View File
@@ -5,7 +5,7 @@
.\" Case Western Reserve University
.\" chet.ramey@case.edu
.\"
.\" Last Change: Mon Apr 7 16:59:13 EDT 2025
.\" Last Change: Tue Jul 15 10:19:08 EDT 2025
.\"
.\" For bash_builtins, strip all but "SHELL BUILTIN COMMANDS" section
.\" For rbash, strip all but "RESTRICTED SHELL" section
@@ -21,7 +21,7 @@
.ds zY \" empty
.if \n(zZ=1 .ig zZ
.if \n(zY=1 .ig zY
.TH BASH 1 "2025 April 7" "GNU Bash 5.3"
.TH BASH 1 "2025 July 15" "GNU Bash 5.3"
.\"
.ie \n(.g \{\
.ds ' \(aq
@@ -6933,6 +6933,10 @@ Type
.Q "stty \-a"
at a \fBbash\fP prompt to see your current terminal settings,
including the special control characters (usually \fBcchars\fP).
This binding takes place on each call to \fBreadline\fP,
so changes made by
.Q stty
can take effect.
.TP
.B blink\-matching\-paren (Off)
If set to \fBOn\fP, \fBreadline\fP attempts to briefly move the cursor to an
+1 -1
View File
@@ -3538,7 +3538,7 @@ return_procsub:
/* There aren't any dead jobs in the jobs table, but let's see if there's
one in bgpids. We can do this in posix mode because we'll remove any
one we find from the table, preserving existing semantics. */
if (posixly_correct && (t = bgp_findone ()))
if (posixly_correct && (flags & JWAIT_WAITING) == 0 && (t = bgp_findone ()))
{
pid = t->pid;
r = t->status;
+2 -2
View File
@@ -3143,14 +3143,14 @@ rl_message (const char *format, ...)
#if defined (HAVE_VSNPRINTF)
bneed = vsnprintf (msg_buf, msg_bufsiz, format, args);
if (bneed >= msg_bufsiz - 1)
if (bneed > msg_bufsiz - 1)
{
msg_bufsiz = bneed + 1;
msg_buf = xrealloc (msg_buf, msg_bufsiz);
va_end (args);
va_start (args, format);
vsnprintf (msg_buf, msg_bufsiz - 1, format, args);
vsnprintf (msg_buf, msg_bufsiz, format, args);
}
#else
vsprintf (msg_buf, format, args);
+6 -2
View File
@@ -6,9 +6,9 @@
.\" Case Western Reserve University
.\" chet.ramey@case.edu
.\"
.\" Last Change: Mon Dec 30 11:27:47 EST 2024
.\" Last Change: Tue Jul 15 10:19:29 EDT 2025
.\"
.TH READLINE 3 "2024 December 30" "GNU Readline 8.3"
.TH READLINE 3 "2024 July 15" "GNU Readline 8.3"
.\"
.ie \n(.g \{\
.ds ' \(aq
@@ -473,6 +473,10 @@ Type
.Q "stty \-a"
at a \fBbash\fP prompt to see your current terminal settings,
including the special control characters (usually \fBcchars\fP).
This binding takes place on each call to \fBreadline\fP,
so changes made by
.Q stty
can take effect.
.TP
.B blink\-matching\-paren (Off)
If set to \fBOn\fP, \fBreadline\fP attempts to briefly move the cursor to an
+4
View File
@@ -495,6 +495,10 @@ Readline equivalents.
These override the default Readline bindings described here.
Type @samp{stty -a} at a Bash prompt to see your current terminal settings,
including the special control characters (usually @code{cchars}).
This binding takes place on each call to @code{readline()},
so changes made by
@samp{stty}
can take effect.
@item blink-matching-paren
@vindex blink-matching-paren
+3 -3
View File
@@ -5,7 +5,7 @@ Copyright (C) 1988-2025 Free Software Foundation, Inc.
@set EDITION 8.3
@set VERSION 8.3
@set UPDATED 30 December 2024
@set UPDATED-MONTH December 2024
@set UPDATED 15 July 2025
@set UPDATED-MONTH July 2025
@set LASTCHANGE Mon Dec 30 11:27:03 EST 2024
@set LASTCHANGE Tue Jul 15 10:18:40 EDT 2025
+3 -34
View File
@@ -25,7 +25,7 @@
#endif
#include <bashtypes.h>
#if defined (HAVE_MEMFD_CREATE) || defined (HAVE_SHM_OPEN) || defined (HAVE_SHM_MKSTEMP)
#if defined (HAVE_MEMFD_CREATE) || defined (HAVE_SHM_MKSTEMP)
# include <sys/mman.h>
#endif
#include <filecntl.h>
@@ -41,17 +41,7 @@ static int anonunlink (const char *);
# define MFD_NOEXEC_SEAL 0
#endif
#if defined (HAVE_SHM_OPEN)
#ifndef O_NOFOLLOW
# define O_NOFOLLOW 0
#endif
static int
anonshmunlink (const char *fn)
{
return (shm_unlink (fn));
}
#if defined (HAVE_SHM_MKSTEMP)
static int
anonshmopen (const char *name, int flags, char **fn)
{
@@ -62,35 +52,14 @@ anonshmopen (const char *name, int flags, char **fn)
if (fn)
*fn = 0;
#if defined (HAVE_SHM_MKSTEMP)
fname = savestring ("/shm-XXXXXXXXXX");
fd = shm_mkstemp (fname);
if (fd < 0)
free (fname);
#endif
if (fd < 0)
{
fname = sh_mktmpname (name, flags);
fd = shm_open (fname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW, 0600);
}
if (fd < 0)
{
free (fname);
return fd;
}
if (shm_unlink (fname) < 0)
{
int o;
o = errno;
free (fname);
close (fd);
errno = o;
return -1;
}
if (fn)
*fn = fname;
else
@@ -122,7 +91,7 @@ anonopen (const char *name, int flags, char **fn)
/* Heuristic */
flag = (name && *name == '/') ? MT_TEMPLATE : MT_USETMPDIR;
#if defined (HAVE_SHM_OPEN)
#if defined (HAVE_SHM_MKSTEMP)
fd = anonshmopen (name, flag, fn);
if (fd >= 0)
return fd; /* anonshmopen sets *FN appropriately */
BIN
View File
Binary file not shown.
+185 -361
View File
File diff suppressed because it is too large Load Diff