bash51-004 3.7 KB

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