]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
Bash-5.3 patch 11: fix mapfile problem when callback unsets the variable it is modifying
authorChet Ramey <chet.ramey@case.edu>
Wed, 3 Jun 2026 14:20:22 +0000 (10:20 -0400)
committerChet Ramey <chet.ramey@case.edu>
Wed, 3 Jun 2026 14:20:22 +0000 (10:20 -0400)
builtins/mapfile.def
patchlevel.h

index 31528fa8f44cad78eba68df55fa85bd65fed3c00..71fb8196b74206f2d1ddaede8a6d1f0745fc2057 100644 (file)
@@ -153,9 +153,7 @@ mapfile (int fd, long line_count_goal, long origin, long nskip, long callback_qu
   line_length = 0;
   unbuffered_read = 0;
 
-  /* The following check should be done before reading any lines.  Doing it
-     here allows us to call bind_array_element instead of bind_array_variable
-     and skip the variable lookup on every call. */
+  /* The following check should be done before reading any lines. */
   entry = builtin_find_indexed_array (array_name, flags & MAPF_CLEARARRAY);
   if (entry == 0)
     return EXECUTION_FAILURE;
@@ -201,8 +199,13 @@ mapfile (int fd, long line_count_goal, long origin, long nskip, long callback_qu
          run_callback (callback, array_index, line);
        }
 
-      /* XXX - bad things can happen if the callback modifies ENTRY, e.g.,
-        unsetting it or changing it to a non-indexed-array type. */
+      /* Bad things can happen if the callback modifies ENTRY, e.g.,
+        unsetting it or changing it to a non-indexed-array type, so we
+        look it up again every time we need to assign something */
+      entry = bind_array_variable (array_name, array_index, line, 0);
+      if (entry == 0 || ASSIGN_DISALLOWED (entry, 0))
+       return EXECUTION_FAILURE;
+
       bind_array_element (entry, array_index, line, 0);
 
       /* Have we exceeded # of lines to store? */
index c19339a5ab01e6f2685fda6e49f275b813df3ee9..760e88cbfafccc0379859412ae55e29b09892c9f 100644 (file)
@@ -25,6 +25,6 @@
    regexp `^#define[   ]*PATCHLEVEL', since that's what support/mkversion.sh
    looks for to find the patch level (for the sccs version string). */
 
-#define PATCHLEVEL 10
+#define PATCHLEVEL 11
 
 #endif /* _PATCHLEVEL_H_ */