125-upstream-bash43-025.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. BASH PATCH REPORT
  2. =================
  3. Bash-Release: 4.3
  4. Patch-ID: bash43-025
  5. Bug-Reported-by: Stephane Chazelas <stephane.chazelas@gmail.com>
  6. Bug-Reference-ID:
  7. Bug-Reference-URL:
  8. Bug-Description:
  9. Under certain circumstances, bash will execute user code while processing the
  10. environment for exported function definitions.
  11. Patch (apply with `patch -p0'):
  12. --- a/builtins/common.h
  13. +++ b/builtins/common.h
  14. @@ -33,6 +33,8 @@
  15. #define SEVAL_RESETLINE 0x010
  16. #define SEVAL_PARSEONLY 0x020
  17. #define SEVAL_NOLONGJMP 0x040
  18. +#define SEVAL_FUNCDEF 0x080 /* only allow function definitions */
  19. +#define SEVAL_ONECMD 0x100 /* only allow a single command */
  20. /* Flags for describe_command, shared between type.def and command.def */
  21. #define CDESC_ALL 0x001 /* type -a */
  22. --- a/builtins/evalstring.c
  23. +++ b/builtins/evalstring.c
  24. @@ -308,6 +308,14 @@ parse_and_execute (string, from_file, fl
  25. {
  26. struct fd_bitmap *bitmap;
  27. + if ((flags & SEVAL_FUNCDEF) && command->type != cm_function_def)
  28. + {
  29. + internal_warning ("%s: ignoring function definition attempt", from_file);
  30. + should_jump_to_top_level = 0;
  31. + last_result = last_command_exit_value = EX_BADUSAGE;
  32. + break;
  33. + }
  34. +
  35. bitmap = new_fd_bitmap (FD_BITMAP_SIZE);
  36. begin_unwind_frame ("pe_dispose");
  37. add_unwind_protect (dispose_fd_bitmap, bitmap);
  38. @@ -368,6 +376,9 @@ parse_and_execute (string, from_file, fl
  39. dispose_command (command);
  40. dispose_fd_bitmap (bitmap);
  41. discard_unwind_frame ("pe_dispose");
  42. +
  43. + if (flags & SEVAL_ONECMD)
  44. + break;
  45. }
  46. }
  47. else
  48. --- a/variables.c
  49. +++ b/variables.c
  50. @@ -358,13 +358,11 @@ initialize_shell_variables (env, privmod
  51. temp_string[char_index] = ' ';
  52. strcpy (temp_string + char_index + 1, string);
  53. - if (posixly_correct == 0 || legal_identifier (name))
  54. - parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST);
  55. -
  56. - /* Ancient backwards compatibility. Old versions of bash exported
  57. - functions like name()=() {...} */
  58. - if (name[char_index - 1] == ')' && name[char_index - 2] == '(')
  59. - name[char_index - 2] = '\0';
  60. + /* Don't import function names that are invalid identifiers from the
  61. + environment, though we still allow them to be defined as shell
  62. + variables. */
  63. + if (legal_identifier (name))
  64. + parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
  65. if (temp_var = find_function (name))
  66. {
  67. @@ -381,10 +379,6 @@ initialize_shell_variables (env, privmod
  68. last_command_exit_value = 1;
  69. report_error (_("error importing function definition for `%s'"), name);
  70. }
  71. -
  72. - /* ( */
  73. - if (name[char_index - 1] == ')' && name[char_index - 2] == '\0')
  74. - name[char_index - 2] = '('; /* ) */
  75. }
  76. #if defined (ARRAY_VARS)
  77. # if ARRAY_EXPORT
  78. --- a/subst.c
  79. +++ b/subst.c
  80. @@ -8047,7 +8047,9 @@ comsub:
  81. goto return0;
  82. }
  83. - else if (var = find_variable_last_nameref (temp1))
  84. + else if (var && (invisible_p (var) || var_isset (var) == 0))
  85. + temp = (char *)NULL;
  86. + else if ((var = find_variable_last_nameref (temp1)) && var_isset (var) && invisible_p (var) == 0)
  87. {
  88. temp = nameref_cell (var);
  89. #if defined (ARRAY_VARS)
  90. --- a/patchlevel.h
  91. +++ b/patchlevel.h
  92. @@ -25,6 +25,6 @@
  93. regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
  94. looks for to find the patch level (for the sccs version string). */
  95. -#define PATCHLEVEL 24
  96. +#define PATCHLEVEL 25
  97. #endif /* _PATCHLEVEL_H_ */