0004-bash51-004.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. [From http://mirror.keystealth.org/gnu/bash/bash-5.1-patches/bash51-004]
  2. Signed-off-by: Peter Seiderer <ps.report@gmx.net>
  3. BASH PATCH REPORT
  4. =================
  5. Bash-Release: 5.1
  6. Patch-ID: bash51-004
  7. Bug-Reported-by: oguzismailuysal@gmail.com
  8. Bug-Reference-ID: <CAH7i3LoHGmwaghDpCWRUfcY04gQmeDTH3RiG=bf2b=KbU=gyhw@mail.gmail.com>
  9. Bug-Reference-URL: https://lists.gnu.org/archive/html/bug-bash/2020-12/msg00039.html
  10. Bug-Description:
  11. If a key-value compound array assignment to an associative array is supplied
  12. as an assignment statement argument to the `declare' command that declares the
  13. array, the assignment doesn't perform the correct word expansions.
  14. This patch makes key-value assignment and subscript assignment perform the
  15. same expansions when they're supplied as an argument to `declare'.
  16. Patch (apply with `patch -p0'):
  17. *** ../bash-5.1-patched/arrayfunc.c 2020-10-09 11:38:58.000000000 -0400
  18. --- b/arrayfunc.c 2020-12-11 15:12:22.000000000 -0500
  19. ***************
  20. *** 598,601 ****
  21. --- 598,622 ----
  22. }
  23. }
  24. +
  25. + /* Return non-zero if L appears to be a key-value pair associative array
  26. + compound assignment. */
  27. + int
  28. + kvpair_assignment_p (l)
  29. + WORD_LIST *l;
  30. + {
  31. + return (l && (l->word->flags & W_ASSIGNMENT) == 0 && l->word->word[0] != '['); /*]*/
  32. + }
  33. +
  34. + char *
  35. + expand_and_quote_kvpair_word (w)
  36. + char *w;
  37. + {
  38. + char *t, *r;
  39. +
  40. + t = w ? expand_assignment_string_to_string (w, 0) : 0;
  41. + r = sh_single_quote (t ? t : "");
  42. + free (t);
  43. + return r;
  44. + }
  45. #endif
  46. ***************
  47. *** 641,645 ****
  48. #if ASSOC_KVPAIR_ASSIGNMENT
  49. ! if (assoc_p (var) && nlist && (nlist->word->flags & W_ASSIGNMENT) == 0 && nlist->word->word[0] != '[') /*]*/
  50. {
  51. iflags = flags & ~ASS_APPEND;
  52. --- 662,666 ----
  53. #if ASSOC_KVPAIR_ASSIGNMENT
  54. ! if (assoc_p (var) && kvpair_assignment_p (nlist))
  55. {
  56. iflags = flags & ~ASS_APPEND;
  57. *** ../bash-5.1-patched/arrayfunc.h 2020-04-29 17:24:15.000000000 -0400
  58. --- b/arrayfunc.h 2020-12-11 14:23:50.000000000 -0500
  59. ***************
  60. *** 68,71 ****
  61. --- 68,74 ----
  62. extern void quote_compound_array_list PARAMS((WORD_LIST *, int));
  63. + extern int kvpair_assignment_p PARAMS((WORD_LIST *));
  64. + extern char *expand_and_quote_kvpair_word PARAMS((char *));
  65. +
  66. extern int unbind_array_element PARAMS((SHELL_VAR *, char *, int));
  67. extern int skipsubscript PARAMS((const char *, int, int));
  68. *** ../bash-5.1-patched/subst.c 2020-11-16 10:33:15.000000000 -0500
  69. --- b/subst.c 2020-12-11 15:11:10.000000000 -0500
  70. ***************
  71. *** 11605,11608 ****
  72. --- 11605,11609 ----
  73. WORD_LIST *l, *nl;
  74. char *t;
  75. + int kvpair;
  76. if (flags == 0)
  77. ***************
  78. *** 11619,11622 ****
  79. --- 11620,11627 ----
  80. /* Associative array */
  81. l = parse_string_to_word_list (value, 1, "array assign");
  82. + #if ASSOC_KVPAIR_ASSIGNMENT
  83. + kvpair = kvpair_assignment_p (l);
  84. + #endif
  85. +
  86. /* For associative arrays, with their arbitrary subscripts, we have to
  87. expand and quote in one step so we don't have to search for the
  88. ***************
  89. *** 11624,11627 ****
  90. --- 11629,11638 ----
  91. for (nl = l; nl; nl = nl->next)
  92. {
  93. + #if ASSOC_KVPAIR_ASSIGNMENT
  94. + if (kvpair)
  95. + /* keys and values undergo the same set of expansions */
  96. + t = expand_and_quote_kvpair_word (nl->word->word);
  97. + else
  98. + #endif
  99. if ((nl->word->flags & W_ASSIGNMENT) == 0)
  100. t = sh_single_quote (nl->word->word ? nl->word->word : "");
  101. *** ../bash-5.1/patchlevel.h 2020-06-22 14:51:03.000000000 -0400
  102. --- b/patchlevel.h 2020-10-01 11:01:28.000000000 -0400
  103. ***************
  104. *** 26,30 ****
  105. looks for to find the patch level (for the sccs version string). */
  106. ! #define PATCHLEVEL 3
  107. #endif /* _PATCHLEVEL_H_ */
  108. --- 26,30 ----
  109. looks for to find the patch level (for the sccs version string). */
  110. ! #define PATCHLEVEL 4
  111. #endif /* _PATCHLEVEL_H_ */