2
1

bash-4.2-012.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. BASH PATCH REPORT
  2. =================
  3. Bash-Release: 4.2
  4. Patch-ID: bash42-012
  5. Bug-Reported-by: Rui Santos <rsantos@grupopie.com>
  6. Bug-Reference-ID: <4E04C6D0.2020507@grupopie.com>
  7. Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2011-06/msg00079.html
  8. Bug-Description:
  9. When calling the parser to recursively parse a command substitution within
  10. an arithmetic expansion, the shell overwrote the saved shell input line and
  11. associated state, resulting in a garbled command.
  12. Patch (apply with `patch -p0'):
  13. *** ../bash-4.2-patched/parse.y 2011-02-26 19:19:05.000000000 -0500
  14. --- ./parse.y 2011-06-24 20:08:22.000000000 -0400
  15. ***************
  16. *** 3843,3846 ****
  17. --- 3849,3853 ----
  18. {
  19. sh_parser_state_t ps;
  20. + sh_input_line_state_t ls;
  21. int orig_ind, nc, sflags;
  22. char *ret, *s, *ep, *ostring;
  23. ***************
  24. *** 3850,3857 ****
  25. --- 3857,3866 ----
  26. ostring = string;
  27. + /*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/
  28. sflags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOFREE;
  29. if (flags & SX_NOLONGJMP)
  30. sflags |= SEVAL_NOLONGJMP;
  31. save_parser_state (&ps);
  32. + save_input_line_state (&ls);
  33. /*(*/
  34. ***************
  35. *** 3862,3865 ****
  36. --- 3871,3876 ----
  37. restore_parser_state (&ps);
  38. reset_parser ();
  39. + /* reset_parser clears shell_input_line and associated variables */
  40. + restore_input_line_state (&ls);
  41. if (interactive)
  42. token_to_read = 0;
  43. ***************
  44. *** 5909,5912 ****
  45. --- 5920,5929 ----
  46. ps->echo_input_at_read = echo_input_at_read;
  47. + ps->token = token;
  48. + ps->token_buffer_size = token_buffer_size;
  49. + /* Force reallocation on next call to read_token_word */
  50. + token = 0;
  51. + token_buffer_size = 0;
  52. +
  53. return (ps);
  54. }
  55. ***************
  56. *** 5950,5953 ****
  57. --- 5967,6006 ----
  58. expand_aliases = ps->expand_aliases;
  59. echo_input_at_read = ps->echo_input_at_read;
  60. +
  61. + FREE (token);
  62. + token = ps->token;
  63. + token_buffer_size = ps->token_buffer_size;
  64. + }
  65. +
  66. + sh_input_line_state_t *
  67. + save_input_line_state (ls)
  68. + sh_input_line_state_t *ls;
  69. + {
  70. + if (ls == 0)
  71. + ls = (sh_input_line_state_t *)xmalloc (sizeof (sh_input_line_state_t));
  72. + if (ls == 0)
  73. + return ((sh_input_line_state_t *)NULL);
  74. +
  75. + ls->input_line = shell_input_line;
  76. + ls->input_line_size = shell_input_line_size;
  77. + ls->input_line_len = shell_input_line_len;
  78. + ls->input_line_index = shell_input_line_index;
  79. +
  80. + /* force reallocation */
  81. + shell_input_line = 0;
  82. + shell_input_line_size = shell_input_line_len = shell_input_line_index = 0;
  83. + }
  84. +
  85. + void
  86. + restore_input_line_state (ls)
  87. + sh_input_line_state_t *ls;
  88. + {
  89. + FREE (shell_input_line);
  90. + shell_input_line = ls->input_line;
  91. + shell_input_line_size = ls->input_line_size;
  92. + shell_input_line_len = ls->input_line_len;
  93. + shell_input_line_index = ls->input_line_index;
  94. +
  95. + set_line_mbstate ();
  96. }
  97. *** ../bash-4.2-patched/shell.h 2011-01-06 22:16:55.000000000 -0500
  98. --- ./shell.h 2011-06-24 19:12:25.000000000 -0400
  99. ***************
  100. *** 137,140 ****
  101. --- 139,145 ----
  102. int *token_state;
  103. + char *token;
  104. + int token_buffer_size;
  105. +
  106. /* input line state -- line number saved elsewhere */
  107. int input_line_terminator;
  108. ***************
  109. *** 167,171 ****
  110. --- 172,186 ----
  111. } sh_parser_state_t;
  112. + typedef struct _sh_input_line_state_t {
  113. + char *input_line;
  114. + int input_line_index;
  115. + int input_line_size;
  116. + int input_line_len;
  117. + } sh_input_line_state_t;
  118. +
  119. /* Let's try declaring these here. */
  120. extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
  121. extern void restore_parser_state __P((sh_parser_state_t *));
  122. +
  123. + extern sh_input_line_state_t *save_input_line_state __P((sh_input_line_state_t *));
  124. + extern void restore_input_line_state __P((sh_input_line_state_t *));
  125. *** ../bash-4.2-patched/patchlevel.h Sat Jun 12 20:14:48 2010
  126. --- ./patchlevel.h Thu Feb 24 21:41:34 2011
  127. ***************
  128. *** 26,30 ****
  129. looks for to find the patch level (for the sccs version string). */
  130. ! #define PATCHLEVEL 11
  131. #endif /* _PATCHLEVEL_H_ */
  132. --- 26,30 ----
  133. looks for to find the patch level (for the sccs version string). */
  134. ! #define PATCHLEVEL 12
  135. #endif /* _PATCHLEVEL_H_ */