You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
6.2 KiB

  1. BASH PATCH REPORT
  2. =================
  3. Bash-Release: 5.0
  4. Patch-ID: bash50-010
  5. Bug-Reported-by: Thorsten Glaser <tg@mirbsd.de>
  6. Bug-Reference-ID: <156622962831.19438.16374961114836556294.reportbug@tglase.lan.tarent.de>
  7. Bug-Reference-URL: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=935115
  8. Bug-Description:
  9. Bash-5.0 changed the way assignment statements preceding special builtins
  10. and shell functions were handled in posix mode. They automatically created
  11. or modified global variables instead of modifying existing local variables
  12. as in bash-4.4.
  13. The bash-4.4 posix-mode semantics were buggy, and resulted in creating
  14. local variables where they were not intended and modifying global variables
  15. and local variables simultaneously.
  16. The bash-5.0 changes were intended to fix this issue, but did not preserve
  17. enough backwards compatibility. The posix standard also changed what it
  18. required in these cases, so bash-5.0 is not bound by the strict conformance
  19. requirements that existed in previous issues of the standard.
  20. This patch modifies the bash-5.0 posix mode behavior in an effort to restore
  21. some backwards compatibility and rationalize the behavior in the presence of
  22. local variables. It
  23. 1. Changes the assignment semantics to be more similar to standalone assignment
  24. statements: assignments preceding a function call or special builtin while
  25. executing in a shell function will modify the value of a local variable
  26. with the same name for the duration of the function's execution;
  27. 2. Changes assignments preceding shell function calls or special builtins
  28. from within a shell function to no longer create or modify global variables
  29. in the presence of a local variable with the same name;
  30. 3. Assignment statements preceding a shell function call or special builtin
  31. at the global scope continue to modify the (global) calling environment,
  32. but are unaffected by assignments preceding function calls or special
  33. builtins within a function, as described in item 2. This is also similar
  34. to the behavior of a standalone assignment statement.
  35. Patch (apply with `patch -p0'):
  36. *** a/variables.c 2018-12-18 11:07:21.000000000 -0500
  37. --- b/variables.c 2019-08-22 10:53:44.000000000 -0400
  38. ***************
  39. *** 4461,4467 ****
  40. /* Take a variable from an assignment statement preceding a posix special
  41. ! builtin (including `return') and create a global variable from it. This
  42. ! is called from merge_temporary_env, which is only called when in posix
  43. ! mode. */
  44. static void
  45. push_posix_temp_var (data)
  46. --- 4461,4467 ----
  47. /* Take a variable from an assignment statement preceding a posix special
  48. ! builtin (including `return') and create a variable from it as if a
  49. ! standalone assignment statement had been performed. This is called from
  50. ! merge_temporary_env, which is only called when in posix mode. */
  51. static void
  52. push_posix_temp_var (data)
  53. ***************
  54. *** 4473,4486 ****
  55. var = (SHELL_VAR *)data;
  56. ! binding_table = global_variables->table;
  57. ! if (binding_table == 0)
  58. ! binding_table = global_variables->table = hash_create (VARIABLES_HASH_BUCKETS);
  59. !
  60. ! v = bind_variable_internal (var->name, value_cell (var), binding_table, 0, ASS_FORCE|ASS_NOLONGJMP);
  61. /* global variables are no longer temporary and don't need propagating. */
  62. ! var->attributes &= ~(att_tempvar|att_propagate);
  63. if (v)
  64. ! v->attributes |= var->attributes;
  65. if (find_special_var (var->name) >= 0)
  66. --- 4473,4497 ----
  67. var = (SHELL_VAR *)data;
  68. ! /* Just like do_assignment_internal(). This makes assignments preceding
  69. ! special builtins act like standalone assignment statements when in
  70. ! posix mode, satisfying the posix requirement that this affect the
  71. ! "current execution environment." */
  72. ! v = bind_variable (var->name, value_cell (var), ASS_FORCE|ASS_NOLONGJMP);
  73. !
  74. ! /* If this modifies an existing local variable, v->context will be non-zero.
  75. ! If it comes back with v->context == 0, we bound at the global context.
  76. ! Set binding_table appropriately. It doesn't matter whether it's correct
  77. ! if the variable is local, only that it's not global_variables->table */
  78. ! binding_table = v->context ? shell_variables->table : global_variables->table;
  79. /* global variables are no longer temporary and don't need propagating. */
  80. ! if (binding_table == global_variables->table)
  81. ! var->attributes &= ~(att_tempvar|att_propagate);
  82. !
  83. if (v)
  84. ! {
  85. ! v->attributes |= var->attributes;
  86. ! v->attributes &= ~att_tempvar; /* not a temp var now */
  87. ! }
  88. if (find_special_var (var->name) >= 0)
  89. ***************
  90. *** 4576,4587 ****
  91. {
  92. int i;
  93. tempvar_list = strvec_create (HASH_ENTRIES (temporary_env) + 1);
  94. tempvar_list[tvlist_ind = 0] = 0;
  95. !
  96. ! hash_flush (temporary_env, pushf);
  97. ! hash_dispose (temporary_env);
  98. temporary_env = (HASH_TABLE *)NULL;
  99. tempvar_list[tvlist_ind] = 0;
  100. --- 4587,4601 ----
  101. {
  102. int i;
  103. + HASH_TABLE *disposer;
  104. tempvar_list = strvec_create (HASH_ENTRIES (temporary_env) + 1);
  105. tempvar_list[tvlist_ind = 0] = 0;
  106. !
  107. ! disposer = temporary_env;
  108. temporary_env = (HASH_TABLE *)NULL;
  109. + hash_flush (disposer, pushf);
  110. + hash_dispose (disposer);
  111. +
  112. tempvar_list[tvlist_ind] = 0;
  113. *** a/tests/varenv.right 2018-12-17 15:39:48.000000000 -0500
  114. --- b/tests/varenv.right 2019-08-22 16:05:25.000000000 -0400
  115. ***************
  116. *** 147,153 ****
  117. outside: declare -- var="one"
  118. inside: declare -x var="value"
  119. ! outside: declare -x var="value"
  120. ! inside: declare -- var="local"
  121. ! outside: declare -x var="global"
  122. foo=<unset> environment foo=
  123. foo=foo environment foo=foo
  124. --- 147,153 ----
  125. outside: declare -- var="one"
  126. inside: declare -x var="value"
  127. ! outside: declare -- var="outside"
  128. ! inside: declare -x var="global"
  129. ! outside: declare -- var="outside"
  130. foo=<unset> environment foo=
  131. foo=foo environment foo=foo
  132. *** a/patchlevel.h 2016-06-22 14:51:03.000000000 -0400
  133. --- b/patchlevel.h 2016-10-01 11:01:28.000000000 -0400
  134. ***************
  135. *** 26,30 ****
  136. looks for to find the patch level (for the sccs version string). */
  137. ! #define PATCHLEVEL 9
  138. #endif /* _PATCHLEVEL_H_ */
  139. --- 26,30 ----
  140. looks for to find the patch level (for the sccs version string). */
  141. ! #define PATCHLEVEL 10
  142. #endif /* _PATCHLEVEL_H_ */