Merge pull request #1760 from salzmdan/master
[feed/packages.git] / utils / bash / patches / 131-upstream-bash43-031.patch
1 BASH PATCH REPORT
2 =================
3
4 Bash-Release: 4.3
5 Patch-ID: bash43-031
6
7 Bug-Reported-by: lolilolicon <lolilolicon@gmail.com>
8 Bug-Reference-ID: <CAMtVo_Nz=32Oq=zWTb6=+8gUNXOo2rRvud1W4oPnA-cgVk_ZqQ@mail.gmail.com>
9 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2014-08/msg00139.html
10
11 Bug-Description:
12
13 The new nameref assignment functionality introduced in bash-4.3 did not perform
14 enough validation on the variable value and would create variables with
15 invalid names.
16
17 Patch (apply with `patch -p0'):
18
19 --- a/subst.h
20 +++ b/subst.h
21 @@ -47,6 +47,7 @@
22 #define ASS_MKASSOC 0x0004
23 #define ASS_MKGLOBAL 0x0008 /* force global assignment */
24 #define ASS_NAMEREF 0x0010 /* assigning to nameref variable */
25 +#define ASS_FROMREF 0x0020 /* assigning from value of nameref variable */
26
27 /* Flags for the string extraction functions. */
28 #define SX_NOALLOC 0x0001 /* just skip; don't return substring */
29 --- a/variables.c
30 +++ b/variables.c
31 @@ -2516,10 +2516,27 @@ bind_variable_internal (name, value, tab
32 HASH_TABLE *table;
33 int hflags, aflags;
34 {
35 - char *newval;
36 + char *newname, *newval;
37 SHELL_VAR *entry;
38 +#if defined (ARRAY_VARS)
39 + arrayind_t ind;
40 + char *subp;
41 + int sublen;
42 +#endif
43
44 + newname = 0;
45 +#if defined (ARRAY_VARS)
46 + if ((aflags & ASS_FROMREF) && (hflags & HASH_NOSRCH) == 0 && valid_array_reference (name))
47 + {
48 + newname = array_variable_name (name, &subp, &sublen);
49 + if (newname == 0)
50 + return (SHELL_VAR *)NULL; /* XXX */
51 + entry = hash_lookup (newname, table);
52 + }
53 + else
54 +#endif
55 entry = (hflags & HASH_NOSRCH) ? (SHELL_VAR *)NULL : hash_lookup (name, table);
56 +
57 /* Follow the nameref chain here if this is the global variables table */
58 if (entry && nameref_p (entry) && (invisible_p (entry) == 0) && table == global_variables->table)
59 {
60 @@ -2550,6 +2567,16 @@ bind_variable_internal (name, value, tab
61 var_setvalue (entry, make_variable_value (entry, value, 0));
62 }
63 }
64 +#if defined (ARRAY_VARS)
65 + else if (entry == 0 && newname)
66 + {
67 + entry = make_new_array_variable (newname); /* indexed array by default */
68 + if (entry == 0)
69 + return entry;
70 + ind = array_expand_index (name, subp, sublen);
71 + bind_array_element (entry, ind, value, aflags);
72 + }
73 +#endif
74 else if (entry == 0)
75 {
76 entry = make_new_variable (name, table);
77 @@ -2670,7 +2697,8 @@ bind_variable (name, value, flags)
78 normal. */
79 if (nameref_cell (nv) == 0)
80 return (bind_variable_internal (nv->name, value, nvc->table, 0, flags));
81 - return (bind_variable_internal (nameref_cell (nv), value, nvc->table, 0, flags));
82 + /* XXX - bug here with ref=array[index] */
83 + return (bind_variable_internal (nameref_cell (nv), value, nvc->table, 0, flags|ASS_FROMREF));
84 }
85 else
86 v = nv;
87 --- a/patchlevel.h
88 +++ b/patchlevel.h
89 @@ -25,6 +25,6 @@
90 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
91 looks for to find the patch level (for the sccs version string). */
92
93 -#define PATCHLEVEL 30
94 +#define PATCHLEVEL 31
95
96 #endif /* _PATCHLEVEL_H_ */