]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
more fixes for using bool and the stdckdint functions for integer overflow; another...
authorChet Ramey <chet.ramey@case.edu>
Thu, 28 Mar 2024 16:16:15 +0000 (12:16 -0400)
committerChet Ramey <chet.ramey@case.edu>
Thu, 28 Mar 2024 16:16:15 +0000 (12:16 -0400)
33 files changed:
CWRU/CWRU.chlog
MANIFEST
Makefile.in
bashansi.h
braces.c
builtins/fc.def
builtins/help.def
builtins/history.def
builtins/printf.def
configure
configure.ac
doc/bash.1
doc/bashref.texi
doc/version.texi
externs.h
lib/readline/shell.c
lib/sh/Makefile.in
lib/sh/fmtulong.c
lib/sh/getcwd.c
lib/sh/makepath.c
lib/sh/reallocarray.c [new file with mode: 0644]
lib/sh/snprintf.c
lib/sh/stringvec.c
lib/sh/strtod.c
lib/sh/strtol.c
parse.y
po/de.gmo
po/de.po
shell.h
test.c
unwind_prot.c
xmalloc.c
xmalloc.h

index 725b576bb6c589858e82816f00f3dd9e4c66dd29..8f18eaa1f3e0cf8271f61ca5c36596bd01fbb022 100644 (file)
@@ -8920,6 +8920,80 @@ test.c
        - term: if we see a left paren, scan forward for a closing right paren
          and use posixtest() if there are 1-4 arguments between the parens to
          avoid ambiguous behavior for expressions like true -a \( ! -a \),
-         which a user would expect to return false instead of an error
-         message
-         Picked up from coreutils test
+         which, though it's horribly ambiguous,  a user would expect to
+         return false instead of an error message
+         Picked up from coreutils-9.2 test
+
+                                  3/25
+                                  ----
+bashansi.c
+       - HAVE_C_BOOL: prefer if defined, fall back to stdbool.h if bool isn't
+         a compiler builtin
+
+braces.c
+       - mkseq: simplify break condition
+
+builtins/printf.def
+       - decodeint: let the caller decide what to do with an overflow return,
+         don't return -1 after calling report_erange(). This will honor a
+         precision even if the field width overflows
+       - printf_builtin: check for overflow when adjusting precision for
+         string length with %Q
+       - printstr,printwidestr: now that the code uses decodeint, we don't
+         need to check the precision against INT_MAX
+
+bashansi.h
+       - include stddef.h if we have it, otherwise define replacements for
+         NULL and offsetof()
+
+builtins/help.def,lib/sh/fmtulong.c,lib/sh/getcwd.c,lib/sh/makepath.c,
+lib/sh/snprintf.c,lib/sh/strtod.c,lib/sh/strtol.c,unwind_prot.c,
+lib/readline/shell.c
+       - include bashansi.h instead of stddef.h, or remove a stddef.h include
+         if bashansi.h is already included
+       - remove extra definitions that appear in stddef.h or bashansi.h
+
+lib/sh/reallocarray.c,externs.h
+       - implementation of reallocarray(), originally from OpenBSD, from
+         Paul Eggert
+
+configure.ac
+       - use AC_REPLACE_FUNCS for reallocarray
+
+xmalloc.c,xmalloc.h
+       - xreallocarray: implementation of reallocarray that uses xrealloc
+       - sh_xreallocarray: implementation of reallocarray that uses
+         sh_xrealloc and has file and line information for error messages
+
+lib/sh/stringvec.c
+       - strvec_create, strvec_resize: rewrite in terms of xreallocarray
+       - strvec_mcreate, strvec_mresize: rewrite in terms of reallocarray
+       - strvec_remove, strvec_search, strvec_copy, strvec_from_word_list,
+         strvec_to_word_list: use size_t instead of int where appropriate
+
+lib/sh/stringvec.c,externs.h
+       - strvec_search: return a value of type ptrdiff_t, since size_t is
+         unsigned and we want to return -1 if not found
+
+         All from a report and patch by Paul Eggert <eggert@cs.ucla.edu>
+
+test.c
+       - term: change paren scan algorithm to count open and close parens so
+         we handle nested subexpressions. Still not compatible in the case
+         of something like test true -a \( ! -a \) \)
+
+                                  3/27
+                                  ----
+parse.y
+       - flush_parser_state: new function, deallocates the members of a
+         parser state struct that are dynamically allocated
+       - parse_comsub: call flush_parser_state in places where we will
+         return an error or jump to the top level
+         Fixes memory leaks on error reported by bug_reports00@protonmail.com
+
+Makefile.in
+       - CREATED_MACOS: list of dSYM directories created by building and
+         testing
+       - distclean,maintainer-clean: remove $(CREATED_HEADERS) and
+         $(CREATED_MACOS)
+       - maintainer-clean: remove ctags/etags files
index c1f079eedfe3ccecbc783f71dc709942bb8ecfdb..1d4dee596765b7dbc9be8407ba4fdf1a4a298ecb 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -466,6 +466,7 @@ lib/sh/oslib.c              f
 lib/sh/pathcanon.c     f
 lib/sh/pathphys.c      f
 lib/sh/random.c                f
+lib/sh/reallocarray.c  f
 lib/sh/rename.c                f
 lib/sh/setlinebuf.c    f
 lib/sh/shmatch.c       f
index 7499e89774dcae1749021ab297056becb1eb71e6..8069162aece00de8146850892a88d43c18eaa566 100644 (file)
@@ -1,4 +1,4 @@
-# Makefile for bash-5.3, version 5.4
+# Makefile for bash-5.3, version 5.5
 #
 # Copyright (C) 1996-2024 Free Software Foundation, Inc.
 
@@ -583,6 +583,8 @@ CREATED_SUPPORT = signames.h recho$(EXEEXT) zecho$(EXEEXT) printenv$(EXEEXT) \
                  mksignames$(EXEEXT) lsignames.h \
                  mksyntax${EXEEXT} syntax.c $(VERSPROG) $(VERSOBJ) \
                  buildversion.o mksignames.o signames.o buildsignames.o
+CREATED_MACOS = recho.dSYM zecho.dSYM printenv.dSYM xcase.dSYM \
+                bashversion.dSYM mksyntax.dSYM ${DEFDIR}/psize.aux.dSYM
 CREATED_CONFIGURE = config.h config.cache config.status config.log \
                    stamp-h po/POTFILES config.status.lineno
 CREATED_MAKEFILES = Makefile builtins/Makefile doc/Makefile \
@@ -949,6 +951,7 @@ clean:      basic-clean
        -( cd $(PO_DIR) ; $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ )
        -( cd $(LOADABLES_DIR) && $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ )
        $(RM) $(CREATED_SUPPORT)
+       $(RM) -rf $(CREATED_MACOS)
 
 mostlyclean: basic-clean
        ( cd $(DOCDIR) && $(MAKE) $(MFLAGS) $@ )
@@ -970,7 +973,8 @@ distclean:  basic-clean maybe-clean
        -( cd $(PO_DIR) ; $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ )
        -( cd $(LOADABLES_DIR) && $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ )
        $(RM) $(CREATED_CONFIGURE) tags TAGS 
-       $(RM) $(CREATED_SUPPORT) Makefile $(CREATED_MAKEFILES) pathnames.h
+       $(RM) $(CREATED_SUPPORT) Makefile $(CREATED_MAKEFILES) $(CREATED_HEADERS)
+       $(RM) -rf $(CREATED_MACOS)
 
 maintainer-clean:      basic-clean
        @echo This command is intended for maintainers to use.
@@ -984,8 +988,9 @@ maintainer-clean:   basic-clean
        done
        -( cd $(PO_DIR) ; $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ )
        -( cd $(LOADABLES_DIR) && $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ )
-       $(RM) $(CREATED_CONFIGURE) $(CREATED_MAKEFILES)
-       $(RM) $(CREATED_SUPPORT) Makefile pathnames.h
+       $(RM) $(CREATED_CONFIGURE) Makefile $(CREATED_MAKEFILES) tags TAGS
+       $(RM) $(CREATED_SUPPORT) $(CREATED_HEADERS)
+       $(RM) -rf $(CREATED_MACOS)
 
 maybe-clean:
        -if test X"`cd $(topdir) && pwd -P`" != X"`cd $(BUILD_DIR) && pwd -P`" ; then \
index 4feaadfb3f1b407b3fc138d609b23b5e46f88faf..16772d226e33546ea62d00bf3390a334dc003651 100644 (file)
 #  include "ansi_stdlib.h"
 #endif /* !HAVE_STDLIB_H */
 
-/* Prefer stdbool.h if we have it, maybe have to rethink this later */
-#if defined (HAVE_STDBOOL_H)
-#  include <stdbool.h>
-#else
-#  ifndef HAVE_C_BOOL
+/* If bool is not a compiler builtin, prefer stdbool.h if we have it */
+#if !defined (HAVE_C_BOOL)
+#  if defined (HAVE_STDBOOL_H)
+#    include <stdbool.h>
+#  else
 #    undef bool
 typedef unsigned char bool;
+#    define true 1
+#    define false 0
 #  endif
 #endif
 
+/* Include <stddef.h>, or define substitutes (config.h handles ptrdiff_t). */
+#ifdef HAVE_STDDEF_H
+#  include <stddef.h>
+#endif
+/* Substitutes for definitions in stddef.h */
+#ifndef NULL
+#  define NULL 0
+#endif
+#ifndef offsetof
+#  define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
 #endif /* !_BASHANSI_H_ */
index 444807a71eb3ac4b3d13c59245c7bfab7f9395e3..099312e44256c6b063ff0d2d3c7b713880673cee 100644 (file)
--- a/braces.c
+++ b/braces.c
@@ -399,7 +399,7 @@ mkseq (intmax_t start, intmax_t end, intmax_t incr, int type, size_t width)
       QUIT;
 #endif
       if (type == ST_INT)
-       result[i++] = t = itos (n);
+       t = itos (n);
       else if (type == ST_ZINT)
        {
          size_t tlen;
@@ -419,7 +419,6 @@ mkseq (intmax_t start, intmax_t end, intmax_t incr, int type, size_t width)
                  memset (t + (n < 0), '0', width - tlen);
                }
            }
-         result[i++] = t;
        }
       else
        {
@@ -428,9 +427,10 @@ mkseq (intmax_t start, intmax_t end, intmax_t incr, int type, size_t width)
              t[0] = n;
              t[1] = '\0';
            }
-         result[i++] = t;
        }
 
+      result[i++] = t;
+
       /* We failed to allocate memory for this number, so we bail. */
       if (t == 0)
        {
@@ -445,11 +445,8 @@ mkseq (intmax_t start, intmax_t end, intmax_t incr, int type, size_t width)
        }
 
       n += incr;
-
-      if (i == nelem - 1)
-       break;
     }
-  while (1);
+  while (i < nelem - 1);
 
   result[i] = (char *)0;
   return (result);
index d5f7beaa459db8124e6ab7e3119f388916d86496..17121037a6c33cc19cf87e973e21c086d89b682f 100644 (file)
@@ -1,7 +1,7 @@
 This file is fc.def, from which is created fc.c.
 It implements the builtin "fc" in Bash.
 
-Copyright (C) 1987-2023 Free Software Foundation, Inc.
+Copyright (C) 1987-2024 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -45,6 +45,8 @@ A useful alias to use with this is r='fc -s', so that typing `r cc'
 runs the last command beginning with `cc' and typing `r' re-executes
 the last command.
 
+The history builtin also operates on the history list.
+
 Exit Status:
 Returns success or status of executed command; non-zero if an error occurs.
 $END
index 6195831bd0f0d47bce9f358c77017d6cbe7dc21c..0831cab006340dcb6e02de9444ba4c3db3807ee3 100644 (file)
@@ -1,7 +1,7 @@
 This file is help.def, from which is created help.c.
 It implements the builtin "help" in Bash.
 
-Copyright (C) 1987-2023 Free Software Foundation, Inc.
+Copyright (C) 1987-2024 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -58,7 +58,7 @@ $END
 #include <errno.h>
 
 #include <filecntl.h>
-#include <stddef.h>
+#include "../bashansi.h"
 
 #include "../bashintl.h"
 
index 69203a92f312ac88d57e8b016dc25dfafeba5bd9..ae64726a9558a17fd9efddfc260d73d851139c75 100644 (file)
@@ -1,7 +1,7 @@
 This file is history.def, from which is created history.c.
 It implements the builtin "history" in Bash.
 
-Copyright (C) 1987-2023 Free Software Foundation, Inc.
+Copyright (C) 1987-2024 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -50,6 +50,8 @@ if HISTFILE has a value, that is used. If FILENAME is not supplied
 and HISTFILE is unset or null, the -a, -n, -r, and -w options have
 no effect and return success.
 
+The fc builtin also operates on the history list.
+
 If the HISTTIMEFORMAT variable is set and not null, its value is used
 as a format string for strftime(3) to print the time stamp associated
 with each displayed history entry.  No time stamps are printed otherwise.
index c033407be9f6139b8729e38d657d0ae51d2b9ef6..91b76d6e0cd3db7861edf04571a849d5984ad4e2 100644 (file)
@@ -262,10 +262,7 @@ decodeint (char **str, int diagnose, int overflow_return)
       v |= ckd_add (&pr, pr, *ps - '0');
     }
   if (v && diagnose)
-    {
-      report_erange (*str, ps);
-      return -1;
-    }
+    report_erange (*str, ps);
 
   *str = ps;
   return (v ? overflow_return : pr);
@@ -699,8 +696,12 @@ printf_builtin (WORD_LIST *list)
                    slen = strlen (xp);
                    if (convch == 'Q')
                      {
-                       if (slen > precision)
-                         precision = slen;
+                       /* check for string length overflow when adjusting precision */
+                       if (ckd_add (&precision, slen, 0))
+                         {
+                           builtin_error (_("%%Q: string length: %s"), strerror (ERANGE));
+                           precision = -1;
+                         }
                      }             
                    /* Use printstr to get fieldwidth and precision right. */
                    r = printstr (start, xp, slen, fieldwidth, precision);
@@ -904,7 +905,7 @@ printstr (char *fmt, char *string, size_t len, int fieldwidth, int precision)
          pr = decodeint (&fmt, 1, -1);
          /* pr < precision means we adjusted precision in printf_builtin
             for the quoted string length (%Q), so we use the adjusted value */
-         if (pr < precision && precision < INT_MAX)
+         if (pr < precision)
            pr = precision;
        }
       else
@@ -1002,7 +1003,7 @@ printwidestr (char *fmt, wchar_t *wstring, size_t len, int fieldwidth, int preci
          pr = decodeint (&fmt, 1, -1);
          /* pr < precision means we adjusted precision in printf_builtin
             for the quoted string length (%Q), so we use the adjusted value */
-         if (pr < precision && precision < INT_MAX)
+         if (pr < precision)
            pr = precision;
        }
       else
index 6f6c0150ac4afb64186e5e77483896da9de87035..d70968da986dfb7dccaeaf767439c7818e9dfb5c 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac for Bash 5.3, version 5.062.
+# From configure.ac for Bash 5.3, version 5.063.
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.71 for bash 5.3-devel.
 #
@@ -15865,6 +15865,20 @@ esac
 
 fi
 
+ac_fn_c_check_func "$LINENO" "reallocarray" "ac_cv_func_reallocarray"
+if test "x$ac_cv_func_reallocarray" = xyes
+then :
+  printf "%s\n" "#define HAVE_REALLOCARRAY 1" >>confdefs.h
+
+else $as_nop
+  case " $LIBOBJS " in
+  *" reallocarray.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS reallocarray.$ac_objext"
+ ;;
+esac
+
+fi
+
 
 ac_fn_c_check_header_compile "$LINENO" "libaudit.h" "ac_cv_header_libaudit_h" "$ac_includes_default"
 if test "x$ac_cv_header_libaudit_h" = xyes
index dd276b68e1fff2f851863a0426689a58b80cbfda..b1fd617a277e3f7b2ba7924db0c9e4eef20c42bb 100644 (file)
@@ -21,7 +21,7 @@ dnl Process this file with autoconf to produce a configure script.
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-AC_REVISION([for Bash 5.3, version 5.062])dnl
+AC_REVISION([for Bash 5.3, version 5.063])dnl
 
 define(bashvers, 5.3)
 define(relstatus, devel)
@@ -887,6 +887,7 @@ AC_REPLACE_FUNCS(dprintf)
 AC_REPLACE_FUNCS(strchrnul)
 AC_REPLACE_FUNCS(strdup)
 AC_REPLACE_FUNCS(strlcpy)
+AC_REPLACE_FUNCS(reallocarray)
 
 AC_CHECK_HEADERS(libaudit.h)
 AC_CHECK_DECLS([AUDIT_USER_TTY],,, [[#include <linux/audit.h>]])
index 65bd81cee47440693866910a0c9e9e9768211bb2..3a03578bd49fd6e5c705fe5faecc1c90a94ac2db 100644 (file)
@@ -5,14 +5,14 @@
 .\"    Case Western Reserve University
 .\"    chet.ramey@case.edu
 .\"
-.\"    Last Change: Mon Feb 19 16:52:45 EST 2024
+.\"    Last Change: Mon Mar 25 10:56:35 EDT 2024
 .\"
 .\" bash_builtins, strip all but Built-Ins section
 .\" avoid a warning about an undefined register
 .\" .if !rzY .nr zY 0
 .if \n(zZ=1 .ig zZ
 .if \n(zY=1 .ig zY
-.TH BASH 1 "2024 February 19" "GNU Bash 5.3"
+.TH BASH 1 "2024 March 25" "GNU Bash 5.3"
 .\"
 .\" There's some problem with having a `@'
 .\" in a tagged paragraph with the BSD man macros.
@@ -3683,6 +3683,7 @@ Produces a possibly-quoted version of the value of \fIparameter\fP,
 except that it prints the values of
 indexed and associative arrays as a sequence of quoted key-value pairs
 (see \fBArrays\fP above).
+The keys and values are quoted in a format that can be reused as input.
 .TP
 .B a
 The expansion is a string consisting of flag values representing
index adfd7346339795cd03cf49c4fdf27d9d339a57f2..0cd7097874d1fb0420a1ff43a01e0c9d95e26c1a 100644 (file)
@@ -2609,6 +2609,7 @@ Produces a possibly-quoted version of the value of @var{parameter},
 except that it prints the values of
 indexed and associative arrays as a sequence of quoted key-value pairs
 (@pxref{Arrays}).
+The keys and values are quoted in a format that can be reused as input.
 @item a
 The expansion is a string consisting of flag values representing
 @var{parameter}'s attributes.
index a0bd72ca73e35de0a3215a50ab9254e068772f3f..f5c22ce831bbd1596c38646e5a039ef1c263eefd 100644 (file)
@@ -2,10 +2,10 @@
 Copyright (C) 1988-2024 Free Software Foundation, Inc.
 @end ignore
 
-@set LASTCHANGE Mon Feb 19 16:52:26 EST 2024
+@set LASTCHANGE Mon Mar 25 10:56:49 EDT 2024
 
 @set EDITION 5.3
 @set VERSION 5.3
 
-@set UPDATED 19 February 2024
-@set UPDATED-MONTH February 2024
+@set UPDATED 25 March 2024
+@set UPDATED-MONTH March 2024
index b60fb79e4f75b844e0b92c611f756138e29641c3..bc6f5cc17cc11cccc6a03c547e5f9a95b4a0dd45 100644 (file)
--- a/externs.h
+++ b/externs.h
@@ -333,6 +333,9 @@ extern void seedrand (void);                        /* seed generator randomly */
 extern void seedrand32 (void);
 extern u_bits32_t get_urandom32 (void);
 
+/* declarations for functions defined in lib/sh/reallocarray.c */
+extern void *reallocarray (void *, size_t, size_t);
+
 /* declarations for functions defined in lib/sh/setlinebuf.c */
 #ifdef NEED_SH_SETLINEBUF_DECL
 extern int sh_setlinebuf (FILE *);
@@ -429,7 +432,7 @@ extern void strvec_flush (char **);
 extern void strvec_dispose (char **);
 extern int strvec_remove (char **, const char *);
 extern size_t strvec_len (char * const *);
-extern int strvec_search (char **, const char *);
+extern ptrdiff_t strvec_search (char **, const char *);
 extern char **strvec_copy (char * const *);
 extern int strvec_posixcmp (char **, char **);
 extern int strvec_strcmp (char **, char **);
index 36c91484c94f64dcdb154c829958a3907c363ebd..7c0f9554fb89255084bddc8e61fc742112f95c63 100644 (file)
 extern struct passwd *getpwuid (uid_t);
 #endif /* HAVE_GETPWUID && !HAVE_GETPW_DECLS */
 
-#ifndef NULL
-#  define NULL 0
-#endif
-
 #ifndef CHAR_BIT
 #  define CHAR_BIT 8
 #endif
index f0088477aae775ad95d0e69ce3d345191d2ed4a9..c57052e75920d62677e1f8b86c90aec70b27d8e3 100644 (file)
@@ -95,7 +95,7 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \
           ufuncs.c casemod.c dprintf.c input_avail.c mbscasecmp.c fnxform.c \
           strchrnul.c unicode.c wcswidth.c wcsnwidth.c shmbchar.c strdup.c \
           strvis.c strlcpy.c strscpy.c utf8.c random.c gettimeofday.c \
-          timers.c anonfile.c compat.c
+          timers.c anonfile.c reallocarray.c compat.c
 
 # The header files for this library.
 HSOURCES = 
@@ -178,6 +178,7 @@ oslib.o: oslib.c
 pathcanon.o: pathcanon.c
 pathphys.o: pathphys.c
 random.o: random.c
+reallocarray.o: reallocarray.c
 rename.o: rename.c
 setlinebuf.o: setlinebuf.c
 shmatch.o: shmatch.c
@@ -265,6 +266,7 @@ oslib.o: ${BUILD_DIR}/config.h
 pathcanon.o: ${BUILD_DIR}/config.h
 pathphys.o: ${BUILD_DIR}/config.h
 random.o: ${BUILD_DIR}/config.h
+reallocarray.o: ${BUILD_DIR}/config.h
 rename.o: ${BUILD_DIR}/config.h
 setlinebuf.o: ${BUILD_DIR}/config.h
 shmatch.o: ${BUILD_DIR}/config.h
@@ -691,6 +693,8 @@ anonfile.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
 anonfile.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
 anonfile.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h
 
+reallocarray.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
+
 compat.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
 compat.o: ${topdir}/bashtypes.h
 compat.o: ${BASHINCDIR}/filecntl.h
index 329e48c74516208f960b30da96df02227e9d0ebd..89f0416c8d810d60e2ac51510a14ef91c990bf65 100644 (file)
@@ -1,6 +1,6 @@
 /* fmtulong.c -- Convert unsigned long int to string. */
 
-/* Copyright (C) 1998-2011,2023 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2011,2023-2024 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -31,9 +31,6 @@
 #endif
 
 #include <bashansi.h>
-#ifdef HAVE_STDDEF_H
-#  include <stddef.h>
-#endif
 
 #ifdef HAVE_STDINT_H
 #  include <stdint.h>
index 1a39b9f645fa3d84b685755a02870b6ae4cac98a..a3a1f8b5a5b554336a08c0e6e493d5a3c24837e9 100644 (file)
@@ -1,6 +1,6 @@
 /* getcwd.c -- get pathname of current directory */
 
-/* Copyright (C) 1991, 2022 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 2022, 2024 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -64,10 +64,6 @@ extern int errno;
 #  define lstat stat
 #endif
 
-#if !defined (NULL)
-#  define NULL 0
-#endif
-
 /* If the d_fileno member of a struct dirent doesn't return anything useful,
    we need to check inode number equivalence the hard way.  Return 1 if
    the inode corresponding to PATH/DIR is identical to THISINO. */
index af3adefae11b3cd9551fda9506337caaf1af1d4b..145559b427f37c056f8ad21852d3d31184a364c9 100644 (file)
@@ -1,6 +1,6 @@
 /* makepath.c - glue PATH and DIR together into a full pathname. */
 
-/* Copyright (C) 1987-2020,2022-2023 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2020,2022-2024 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
 
 #include <tilde/tilde.h>
 
-#ifndef NULL
-#  define NULL 0
-#endif
-
 /* MAKE SURE THESE AGREE WITH ../../externs.h. */
 
 #ifndef MP_DOTILDE
diff --git a/lib/sh/reallocarray.c b/lib/sh/reallocarray.c
new file mode 100644 (file)
index 0000000..53d7f77
--- /dev/null
@@ -0,0 +1,44 @@
+/* reallocarray.c - reallocate memory for an array given type size and
+   number of elements */
+
+/* Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This file is part of GNU Bash, the Bourne Again SHell.
+
+   Bash is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   Bash is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Bash.  If not, see <http://www.gnu.org/licenses/>.
+*/
+   
+#include <config.h>
+
+#include "bashansi.h"
+#include <stdckdint.h>
+
+#include <errno.h>
+#if !defined (errno)
+extern int errno;
+#endif
+
+void *
+reallocarray (void *ptr, size_t nmemb, size_t size)
+{
+  size_t nbytes;
+
+  if (ckd_mul (&nbytes, nmemb, size))
+    {
+      errno = ENOMEM;
+      return NULL;
+    }
+               
+  return realloc (ptr, nbytes);
+}
index d0363dcbd93aa3e02bf1a3dc1f2ad60d4e690a59..e8814b958918b8e5e0b6491589740618bdb2f939 100644 (file)
@@ -9,7 +9,7 @@
    Unix snprintf implementation.
    derived from inetutils/libinetutils/snprintf.c Version 1.1
 
-   Copyright (C) 2001-2022 Free Software Foundation, Inc.
+   Copyright (C) 2001-2024 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -94,9 +94,6 @@
 #  include <limits.h>
 #endif
 #include <bashansi.h>
-#ifdef HAVE_STDDEF_H
-#  include <stddef.h>
-#endif
 #include <chartypes.h>
 
 #ifdef HAVE_STDINT_H
index 10ca9da7c3467f2a2ef4a3f3ac7f668c5ebe1d3d..193a26f92e539968ba95b1639faa859eae5d206e 100644 (file)
 char **
 strvec_create (size_t n)
 {
-  size_t nbytes;
-
-  return ckd_mul (&nbytes, n, sizeof (char *)) ? NULL : xmalloc (nbytes);
+  return ((char **)xreallocarray (NULL, n, sizeof (char *)));
 }
 
 /* Allocate an array of strings with room for N members. */
 char **
 strvec_mcreate (size_t n)
 {
-  size_t nbytes;
-
-  return ckd_mul (&nbytes, n, sizeof (char *)) ? NULL : malloc (nbytes);
+  return ((char **)reallocarray (NULL, n, sizeof (char *)));
 }
 
 char **
 strvec_resize (char **array, size_t nsize)
 {
-  size_t nbytes;
-
-  return ckd_mul (&nbytes, nsize, sizeof (char *)) ? NULL : (char **)xrealloc (array, nbytes);
+  return ((char **)xreallocarray (array, nsize, sizeof (char *)));
 }
 
 char **
 strvec_mresize (char **array, size_t nsize)
 {
-  size_t nbytes;
-
-  return ckd_mul (&nbytes, nsize, sizeof (char *)) ? NULL : (char **)realloc (array, nbytes);
+  return ((char **)reallocarray (array, nsize, sizeof (char *)));
 }
 
 /* Return the length of ARRAY, a NULL terminated array of char *. */
@@ -103,7 +95,7 @@ strvec_dispose (char **array)
 int
 strvec_remove (char **array, const char *name)
 {
-  register int i, j;
+  size_t i, j;
   char *x;
 
   if (array == 0)
@@ -123,10 +115,10 @@ strvec_remove (char **array, const char *name)
 
 /* Find NAME in ARRAY.  Return the index of NAME, or -1 if not present.
    ARRAY should be NULL terminated. */
-int
+ptrdiff_t
 strvec_search (char **array, const char *name)
 {
-  int i;
+  size_t i;
 
   for (i = 0; array[i]; i++)
     if (STREQ (name, array[i]))
@@ -139,8 +131,7 @@ strvec_search (char **array, const char *name)
 char **
 strvec_copy (char * const *array)
 {
-  int i;
-  size_t len;
+  size_t i, len;
   char **ret;
 
   len = strvec_len (array);
@@ -212,7 +203,7 @@ strvec_sort (char **array, int posix)
 char **
 strvec_from_word_list (WORD_LIST *list, int alloc, int starting_index, int *ip)
 {
-  int count;
+  size_t count;
   char **array;
 
   count = list_length ((GENERIC_LIST *)list);
@@ -239,7 +230,7 @@ strvec_to_word_list (char **array, int alloc, int starting_index)
 {
   WORD_LIST *list;
   WORD_DESC *w;
-  int i, count;
+  size_t i, count;
 
   if (array == 0 || array[0] == 0)
     return (WORD_LIST *)NULL;
index e6c1c360af3bd7454644c6da8b863742dffc97e5..fec80d2e22b46f3772f1f93f9986cb46d2ac60cb 100644 (file)
@@ -1,6 +1,6 @@
 /* strtod.c - convert string to double-precision floating-point value. */
 
-/* Copyright (C) 1991, 1992, 2022 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 2022-2024 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
    
@@ -41,10 +41,6 @@ extern int errno;
 
 #include <bashansi.h>
 
-#ifndef NULL
-#  define NULL 0
-#endif
-
 #ifndef HUGE_VAL
 #  define HUGE_VAL HUGE
 #endif
index ac30dbd9085796756571e73f66b80dda3ff68f3d..7b6427ec2c2886d0404903e70a5836c7a40d48a8 100644 (file)
@@ -1,6 +1,6 @@
 /* strtol - convert string representation of a number into a long integer value. */
 
-/* Copyright (C) 1991-2001,2022 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2024 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -42,10 +42,6 @@ extern int errno;
 #include <stdc.h>
 #include <bashansi.h>
 
-#ifndef NULL
-#  define NULL 0
-#endif
-
 /* Nonzero if we are defining `strtoul' or `strtoull', operating on
    unsigned integers.  */
 #ifndef UNSIGNED
diff --git a/parse.y b/parse.y
index 3e28d24d91ea43990678bfc49c2dfca99dba9fd5..368c34235ed451120942cffa743ec75d4607815c 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -4497,6 +4497,8 @@ parse_comsub (int qc, int open, int close, size_t *lenp, int flags)
       /* yyparse() has already called yyerror() and reset_parser(), so we set
         PST_NOERROR to avoid a redundant error message. */
       parser_state |= PST_NOERROR;
+
+      flush_parser_state (&ps);
       return (&matched_pair_error);
     }
   else if (r != 0)
@@ -4513,6 +4515,7 @@ parse_comsub (int qc, int open, int close, size_t *lenp, int flags)
          shell_eof_token = ps.eof_token;
          expand_aliases = ps.expand_aliases;
 
+         flush_parser_state (&ps);
          jump_to_top_level (DISCARD);  /* XXX - return (&matched_pair_error)? */
        }
     }
@@ -4529,6 +4532,7 @@ INTERNAL_DEBUG(("current_token (%d) != shell_eof_token (%c)", current_token, she
       shell_eof_token = ps.eof_token;
       expand_aliases = ps.expand_aliases;
 
+      flush_parser_state (&ps);
       return (&matched_pair_error);
     }
 
@@ -7191,6 +7195,27 @@ restore_parser_state (sh_parser_state_t *ps)
   shell_eof_token = ps->eof_token;
 }
 
+/* Free the parts of a parser state struct that have allocated memory. */
+void
+flush_parser_state (sh_parser_state_t *ps)
+{
+  if (ps == 0)
+    return;
+
+  FREE (ps->token_state);
+  ps->token_state = 0;
+
+  if (ps->pipestatus)
+    array_dispose (ps->pipestatus);
+  ps->pipestatus = 0;
+
+  /* We want to free the saved token and leave the current token for error
+     reporting and cleanup. */
+  FREE (ps->token);
+  ps->token = 0;
+  ps->token_buffer_size = 0;
+}
+
 sh_input_line_state_t *
 save_input_line_state (sh_input_line_state_t *ls)
 {
index fbf52b3d98ebe24a361df29dbd729e4cefd88f03..9a5fe86364611da7f93a37062814ad3a4e961ef5 100644 (file)
Binary files a/po/de.gmo and b/po/de.gmo differ
index 5070d8be79a5851650e177b9d3cd9ace7bef0dd1..5292ac00fc8d514af7d4b3250e63da260c398b5b 100644 (file)
--- a/po/de.po
+++ b/po/de.po
@@ -9,7 +9,7 @@ msgstr ""
 "Project-Id-Version: bash 5.2-rc1\n"
 "Report-Msgid-Bugs-To: \n"
 "POT-Creation-Date: 2022-01-11 14:50-0500\n"
-"PO-Revision-Date: 2024-03-11 21:33+0100\n"
+"PO-Revision-Date: 2024-03-24 13:13+0100\n"
 "Last-Translator: Nils Naumann <nau@gmx.net>\n"
 "Language-Team: German <translation-team-de@lists.sourceforge.net>\n"
 "Language: de\n"
@@ -4326,7 +4326,6 @@ msgstr ""
 
 # test
 #: builtins.c:1262
-#, fuzzy
 msgid ""
 "Evaluate conditional expression.\n"
 "    \n"
@@ -4408,13 +4407,13 @@ msgid ""
 msgstr ""
 "Bedingten Ausdruck auswerten.\n"
 "    \n"
-"     Wird Status 0 (wahr) oder 1 (falsch) abhängig vom Ergebnis des\n"
-"     Ausdrucks. Die Ausdrücke können unär oder binär sein. Unäre\n"
+"     Gibt den Status 0 (wahr) oder 1 (falsch) abhängig vom Ergebnis des\n"
+"     Ausdrucks zurück. Die Ausdrücke können unär oder binär sein. Unäre\n"
 "     Ausdrücke werden häufig verwendet, um den Dateistatus zu ermitteln.\n"
 "     Es gibt weiterhin Zeichenketten und numerische Vergeichsoperatoren.\n"
 "    \n"
-"     Das Verhalten von test hängt von der Argumentanzahl ab. Die\n"
-"     bash Handbuchseite enthält deren vollständige Beschreibung.\n"
+"     Das Verhalten hängt von der Argumentanzahl ab. Die bash\n"
+"     Handbuchseite enthält deren vollständige Beschreibung.\n"
 "    \n"
 "     Dateioperatoren:\n"
 "    \n"
@@ -4432,7 +4431,7 @@ msgstr ""
 "       -r Datei Wahr, wenn die Datei für den aktuellen Nutzer lesbar ist.\n"
 "       -s Datei Wahr, wenn die Datei existiert und nicht leer ist.\n"
 "       -S Datei Wahr, wenn die Datei ein Socket ist.\n"
-"       -t FD   Wahr, wenn FD auf einem Terminal geöffnet ist.\n"
+"       -t FD    Wahr, wenn FD auf einem Terminal geöffnet ist.\n"
 "       -u Datei Wahr, wenn das SetUID-Bit der Datei gesetzt ist.\n"
 "       -w Datei Wahr, wenn die Datei für den aktuellen Nutzer schreibbar ist.\n"
 "       -x Datei Wahr, wenn die Datei vom aktuellen Nutzer ausführbar ist.\n"
@@ -4441,23 +4440,23 @@ msgstr ""
 "       -N Datei Wahr, wenn die Datei seit dem letzten Lesen geändert wurde.\n"
 "    \n"
 "       Datei1 -nt Datei2 Wahr, wenn Datei1 neuer als Datei2 ist (gemäß\n"
-"                        Änderungsdatum).\n"
+"                      Änderungsdatum).\n"
 "    \n"
 "       Datei1 -ot Datei2 Wahr, wenn Datei1 älter als Datei2 ist.\n"
 "    \n"
 "       Datei1 -ef Datei2 Wahr, wenn Datei1 ein harter Link zu Datei2 ist.\n"
 "    \n"
-"     Zeichenfolgenoperatoren:\n"
+"     Zeichenkettenoperatoren:\n"
 "    \n"
-"       -z STRING Wahr, wenn die Zeichenfolge leer ist.\n"
+"       -z STRING Wahr, wenn die Zeichenkette leer ist.\n"
 "    \n"
 "       -n STRING\n"
-"          STRING Wahr, wenn die Zeichenfolge nicht leer ist.\n"
+"          STRING Wahr, wenn die Zeichenkette nicht leer ist.\n"
 "    \n"
 "       STRING1 = STRING2\n"
-"                      Wahr, wenn die Zeichenfolgen gleich sind.\n"
+"                      Wahr, wenn die Zeichenketten gleich sind.\n"
 "       STRING1 != STRING2\n"
-"                      Wahr, wenn die Zeichenfolgen nicht gleich sind.\n"
+"                      Wahr, wenn die Zeichenketten nicht gleich sind.\n"
 "       STRING1 < STRING2\n"
 "                      Wahr, wenn STRING1 lexikografisch vor STRING2\n"
 "                      sortiert wird.\n"
@@ -4468,9 +4467,9 @@ msgstr ""
 "     Andere Operatoren:\n"
 "    \n"
 "       -o OPTION Wahr, wenn die Shell-Option OPTION aktiviert ist.\n"
-"       -v VAR Wahr, wenn die Shell-Variable VAR gesetzt ist.\n"
-"       -R VAR Wahr, wenn die Variable gesetzt ist und ein Nameref ist.\n"
-"       ! EXPR Wahr, wenn Ausdruck falsch ist.\n"
+"       -v VAR    Wahr, wenn die Shell-Variable VAR gesetzt ist.\n"
+"       -R VAR    Wahr, wenn die Variable gesetzt ist und ein Nameref ist.\n"
+"       ! EXPR    Wahr, wenn Ausdruck falsch ist.\n"
 "       EXPR1 -a EXPR2 Wahr, wenn sowohl expr1 als auch expr2 wahr sind.\n"
 "       EXPR1 -o EXPR2 Wahr, wenn entweder expr1 ODER expr2 wahr ist.\n"
 "    \n"
@@ -4830,6 +4829,7 @@ msgid ""
 "    Returns the status of the last command executed."
 msgstr ""
 
+# coproc
 #: builtins.c:1672
 msgid ""
 "Create a coprocess named NAME.\n"
@@ -4842,6 +4842,16 @@ msgid ""
 "    Exit Status:\n"
 "    The coproc command returns an exit status of 0."
 msgstr ""
+"Startet einen Koprozess mit dem angegebenen Namen.\n"
+"    \n"
+"     Führt das angegebene Kommando asynchron in einem Kindprozess aus.\n"
+"     Deren Standardaus- und -eingabe werden mit jeweils einer Pipe\n"
+"     verbunden. Deren Dateideskriptoren sind in den Indexen 0 und 1 der\n"
+"     Feldvariable mit dem angegebenen Namen verknüpft.\n"
+"     Der Standardname ist „COPROC“.\n"
+"    \n"
+"     Rückgabewert:\n"
+"     Der Befehl gibt immer 0 zurück."
 
 # function
 #: builtins.c:1686
diff --git a/shell.h b/shell.h
index 6167372695dc96ff30bf267cf0af8bd8515e620f..5a18f4051620eea4defe7db0774905cd8ebef895 100644 (file)
--- a/shell.h
+++ b/shell.h
@@ -1,6 +1,6 @@
 /* shell.h -- The data structures used by the shell */
 
-/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2024 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -239,6 +239,7 @@ extern char *parser_remaining_input (void);
 
 extern sh_parser_state_t *save_parser_state (sh_parser_state_t *);
 extern void restore_parser_state (sh_parser_state_t *);
+extern void flush_parser_state (sh_parser_state_t *);
 
 extern sh_input_line_state_t *save_input_line_state (sh_input_line_state_t *);
 extern void restore_input_line_state (sh_input_line_state_t *);
diff --git a/test.c b/test.c
index 09dc147813293645728ac8036736c39e44c3ee79..467f8ea0d355075b37f35365a4978d611383e0aa 100644 (file)
--- a/test.c
+++ b/test.c
@@ -267,15 +267,23 @@ term (void)
   /* A paren-bracketed argument. */
   if (argv[pos][0] == '(' && argv[pos][1] == '\0') /* ) */
     {
-      int nargs;
+      int nargs, count;
 
       advance (1);
       /* Steal an idea from coreutils and scan forward to check where the right
         paren appears to prevent some ambiguity. If we find a valid sub-
-        expression that has 1-4 arguments, call posixtest on it ( */
-      for (nargs = 1; pos + nargs < argc && ISTOKEN (argv[pos+nargs], ')') == 0; nargs++)
-       ;
-      /* only do this if we have a valid parenthesized expression */
+        expression that has 1-4 arguments, call posixtest on it. Handle
+        nested subexpressions. ( */
+      for (nargs = count = 1; pos + nargs < argc; nargs++)
+       {
+         if (ISTOKEN (argv[pos+nargs], ')'))
+           count--;
+         else if (ISTOKEN (argv[pos+nargs], '('))      /*)*/
+           count++;
+         if (count == 0)
+           break;
+       }
+      /* only use posixtest if we have a valid parenthesized expression */
       value = (pos + nargs < argc && nargs <= 4) ? posixtest (nargs) : expr ();
       if (argv[pos] == 0) /* ( */
        test_syntax_error (_("`)' expected"), (char *)NULL);
index da9218ba3f7e6a979e19a470ea94d37773758adf..4a5195a649751927c9e07eb395088a7b91e89b9c 100644 (file)
@@ -3,7 +3,7 @@
 /* I can't stand it anymore!  Please can't we just write the
    whole Unix system in lisp or something? */
 
-/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2024 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
 #  include <unistd.h>
 #endif
 
-#if defined (HAVE_STDDEF_H)
-#  include <stddef.h>
-#endif
-
-#ifndef offsetof
-#  define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
 #include "command.h"
 #include "general.h"
 #include "unwind_prot.h"
index 3777d53de19b5a76d305415367b6752a2240b5c2..05de38747a0249f51d723e2858c04fe29b3de901 100644 (file)
--- a/xmalloc.c
+++ b/xmalloc.c
 #  include <unistd.h>
 #endif
 
-#if defined (HAVE_STDLIB_H)
-#  include <stdlib.h>
-#else
-#  include "ansi_stdlib.h"
-#endif /* HAVE_STDLIB_H */
+#include "bashansi.h"
+#include <stdckdint.h>
 
 #include "error.h"
 
@@ -131,6 +128,22 @@ xrealloc (PTR_T pointer, size_t bytes)
   return (temp);
 }
 
+/* Reallocate the storage addressed by POINTER so that it is of
+   size NMEMB*SIZE, preserving contents like realloc does.
+   If POINTER is null, allocate new storage.  This is like
+   glibc reallocarray except that it never returns a null pointer;
+   if storage is exhausted it reports an error and exits. */
+PTR_T
+xreallocarray (PTR_T ptr, size_t nmemb, size_t size)
+{
+  size_t nbytes;
+
+  if (ckd_mul (&nbytes, nmemb, size))
+    allocerr ("xreallocarray", (size_t)-1);
+               
+  return xrealloc (ptr, nbytes);
+}
+
 /* Use this as the function to call when adding unwind protects so we
    don't need to know what free() returns. */
 void
@@ -192,6 +205,17 @@ sh_xrealloc (PTR_T pointer, size_t bytes, char *file, int line)
   return (temp);
 }
 
+PTR_T
+sh_xreallocarray (PTR_T ptr, size_t nmemb, size_t size, const char *file, int line)
+{
+  size_t nbytes;
+
+  if (ckd_mul (&nbytes, nmemb, size))
+    sh_allocerr ("xreallocarray", (size_t)-1, file, line);
+               
+  return sh_xrealloc (ptr, nbytes, file, line);
+}
+
 void
 sh_xfree (PTR_T string, char *file, int line)
 {
index d8731305f02e7fc0cbb7410e016336e4bb2d6107..d8fb32a75ad5d7bc80964b090b1b1b8a9afff5c8 100644 (file)
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -1,6 +1,6 @@
 /* xmalloc.h -- defines for the `x' memory allocation functions */
 
-/* Copyright (C) 2001-2023 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2024 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
 /* Allocation functions in xmalloc.c */
 extern PTR_T xmalloc (size_t);
 extern PTR_T xrealloc (void *, size_t);
+extern PTR_T xreallocarray (void *, size_t, size_t);
 extern void xfree (void *);
 
 #if defined(USING_BASH_MALLOC) && !defined (DISABLE_MALLOC_WRAPPERS)
 extern PTR_T sh_xmalloc (size_t, const char *, int);
 extern PTR_T sh_xrealloc (void *, size_t, const char *, int);
+extern PTR_T sh_xreallocarray (void *, size_t, size_t, const char *, int);
 extern void sh_xfree (void *, const char *, int);
 
 #define xmalloc(x)     sh_xmalloc((x), __FILE__, __LINE__)
 #define xrealloc(x, n) sh_xrealloc((x), (n), __FILE__, __LINE__)
+#define xreallocarray(x, n, s) sh_xreallocarray((x), (n), (s), __FILE__, __LINE__)
 #define xfree(x)       sh_xfree((x), __FILE__, __LINE__)
 
 #ifdef free