Ondrej Oprala f6d304
			     BASH PATCH REPORT
Ondrej Oprala f6d304
			     =================
Ondrej Oprala f6d304
Ondrej Oprala f6d304
Bash-Release:	4.3
Ondrej Oprala f6d304
Patch-ID:	bash43-031
Ondrej Oprala f6d304
Ondrej Oprala f6d304
Bug-Reported-by:	lolilolicon <lolilolicon@gmail.com>
Ondrej Oprala f6d304
Bug-Reference-ID:	<CAMtVo_Nz=32Oq=zWTb6=+8gUNXOo2rRvud1W4oPnA-cgVk_ZqQ@mail.gmail.com>
Ondrej Oprala f6d304
Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2014-08/msg00139.html
Ondrej Oprala f6d304
Ondrej Oprala f6d304
Bug-Description:
Ondrej Oprala f6d304
Ondrej Oprala f6d304
The new nameref assignment functionality introduced in bash-4.3 did not perform
Ondrej Oprala f6d304
enough validation on the variable value and would create variables with
Ondrej Oprala f6d304
invalid names.
Ondrej Oprala f6d304
Ondrej Oprala f6d304
Patch (apply with `patch -p0'):
Ondrej Oprala f6d304
Ondrej Oprala f6d304
*** ../bash-4.3-patched/subst.h	2014-01-11 21:02:27.000000000 -0500
Ondrej Oprala f6d304
--- subst.h	2014-09-01 12:16:56.000000000 -0400
Ondrej Oprala f6d304
***************
Ondrej Oprala f6d304
*** 48,51 ****
Ondrej Oprala f6d304
--- 48,52 ----
Ondrej Oprala f6d304
  #define ASS_MKGLOBAL	0x0008	/* force global assignment */
Ondrej Oprala f6d304
  #define ASS_NAMEREF	0x0010	/* assigning to nameref variable */
Ondrej Oprala f6d304
+ #define ASS_FROMREF	0x0020	/* assigning from value of nameref variable */
Ondrej Oprala f6d304
  
Ondrej Oprala f6d304
  /* Flags for the string extraction functions. */
Ondrej Oprala f6d304
*** ../bash-4.3-patched/variables.c	2014-05-15 08:26:50.000000000 -0400
Ondrej Oprala f6d304
--- variables.c	2014-09-01 14:37:44.000000000 -0400
Ondrej Oprala f6d304
***************
Ondrej Oprala f6d304
*** 2504,2511 ****
Ondrej Oprala f6d304
       int hflags, aflags;
Ondrej Oprala f6d304
  {
Ondrej Oprala f6d304
!   char *newval;
Ondrej Oprala f6d304
    SHELL_VAR *entry;
Ondrej Oprala f6d304
  
Ondrej Oprala f6d304
    entry = (hflags & HASH_NOSRCH) ? (SHELL_VAR *)NULL : hash_lookup (name, table);
Ondrej Oprala f6d304
    /* Follow the nameref chain here if this is the global variables table */
Ondrej Oprala f6d304
    if (entry && nameref_p (entry) && (invisible_p (entry) == 0) && table == global_variables->table)
Ondrej Oprala f6d304
--- 2566,2590 ----
Ondrej Oprala f6d304
       int hflags, aflags;
Ondrej Oprala f6d304
  {
Ondrej Oprala f6d304
!   char *newname, *newval;
Ondrej Oprala f6d304
    SHELL_VAR *entry;
Ondrej Oprala f6d304
+ #if defined (ARRAY_VARS)
Ondrej Oprala f6d304
+   arrayind_t ind;
Ondrej Oprala f6d304
+   char *subp;
Ondrej Oprala f6d304
+   int sublen;
Ondrej Oprala f6d304
+ #endif
Ondrej Oprala f6d304
  
Ondrej Oprala f6d304
+   newname = 0;
Ondrej Oprala f6d304
+ #if defined (ARRAY_VARS)
Ondrej Oprala f6d304
+   if ((aflags & ASS_FROMREF) && (hflags & HASH_NOSRCH) == 0 && valid_array_reference (name))
Ondrej Oprala f6d304
+     {
Ondrej Oprala f6d304
+       newname = array_variable_name (name, &subp, &sublen);
Ondrej Oprala f6d304
+       if (newname == 0)
Ondrej Oprala f6d304
+ 	return (SHELL_VAR *)NULL;	/* XXX */
Ondrej Oprala f6d304
+       entry = hash_lookup (newname, table);
Ondrej Oprala f6d304
+     }
Ondrej Oprala f6d304
+   else
Ondrej Oprala f6d304
+ #endif
Ondrej Oprala f6d304
    entry = (hflags & HASH_NOSRCH) ? (SHELL_VAR *)NULL : hash_lookup (name, table);
Ondrej Oprala f6d304
+ 
Ondrej Oprala f6d304
    /* Follow the nameref chain here if this is the global variables table */
Ondrej Oprala f6d304
    if (entry && nameref_p (entry) && (invisible_p (entry) == 0) && table == global_variables->table)
Ondrej Oprala f6d304
***************
Ondrej Oprala f6d304
*** 2538,2541 ****
Ondrej Oprala f6d304
--- 2617,2630 ----
Ondrej Oprala f6d304
        }
Ondrej Oprala f6d304
      }
Ondrej Oprala f6d304
+ #if defined (ARRAY_VARS)
Ondrej Oprala f6d304
+   else if (entry == 0 && newname)
Ondrej Oprala f6d304
+     {
Ondrej Oprala f6d304
+       entry = make_new_array_variable (newname);	/* indexed array by default */
Ondrej Oprala f6d304
+       if (entry == 0)
Ondrej Oprala f6d304
+ 	return entry;
Ondrej Oprala f6d304
+       ind = array_expand_index (name, subp, sublen);
Ondrej Oprala f6d304
+       bind_array_element (entry, ind, value, aflags);
Ondrej Oprala f6d304
+     }
Ondrej Oprala f6d304
+ #endif
Ondrej Oprala f6d304
    else if (entry == 0)
Ondrej Oprala f6d304
      {
Ondrej Oprala f6d304
***************
Ondrej Oprala f6d304
*** 2658,2662 ****
Ondrej Oprala f6d304
  		      if (nameref_cell (nv) == 0)
Ondrej Oprala f6d304
  			return (bind_variable_internal (nv->name, value, nvc->table, 0, flags));
Ondrej Oprala f6d304
! 		      return (bind_variable_internal (nameref_cell (nv), value, nvc->table, 0, flags));
Ondrej Oprala f6d304
  		    }
Ondrej Oprala f6d304
  		  else
Ondrej Oprala f6d304
--- 2747,2752 ----
Ondrej Oprala f6d304
  		      if (nameref_cell (nv) == 0)
Ondrej Oprala f6d304
  			return (bind_variable_internal (nv->name, value, nvc->table, 0, flags));
Ondrej Oprala f6d304
! 		      /* XXX - bug here with ref=array[index] */
Ondrej Oprala f6d304
! 		      return (bind_variable_internal (nameref_cell (nv), value, nvc->table, 0, flags|ASS_FROMREF));
Ondrej Oprala f6d304
  		    }
Ondrej Oprala f6d304
  		  else
Ondrej Oprala f6d304
*** ../bash-4.3/patchlevel.h	2012-12-29 10:47:57.000000000 -0500
Ondrej Oprala f6d304
--- patchlevel.h	2014-03-20 20:01:28.000000000 -0400
Ondrej Oprala f6d304
***************
Ondrej Oprala f6d304
*** 26,30 ****
Ondrej Oprala f6d304
     looks for to find the patch level (for the sccs version string). */
Ondrej Oprala f6d304
  
Ondrej Oprala f6d304
! #define PATCHLEVEL 30
Ondrej Oprala f6d304
  
Ondrej Oprala f6d304
  #endif /* _PATCHLEVEL_H_ */
Ondrej Oprala f6d304
--- 26,30 ----
Ondrej Oprala f6d304
     looks for to find the patch level (for the sccs version string). */
Ondrej Oprala f6d304
  
Ondrej Oprala f6d304
! #define PATCHLEVEL 31
Ondrej Oprala f6d304
  
Ondrej Oprala f6d304
  #endif /* _PATCHLEVEL_H_ */