0017-bash50-017.patch 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. From https://ftp.gnu.org/gnu/bash/bash-5.0-patches/bash55-017
  2. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  3. BASH PATCH REPORT
  4. =================
  5. Bash-Release: 5.0
  6. Patch-ID: bash50-017
  7. Bug-Reported-by: Valentin Lab <valentin.lab@kalysto.org>
  8. Bug-Reference-ID: <ab981b9c-60a5-46d0-b7e6-a6d88b80df50@kalysto.org>
  9. Bug-Reference-URL: https://lists.gnu.org/archive/html/bug-bash/2020-03/msg00062.html
  10. Bug-Description:
  11. There were cases where patch 16 reaped process substitution file descriptors
  12. (or FIFOs) and processes to early. This is a better fix for the problem that
  13. bash50-016 attempted to solve.
  14. Patch (apply with `patch -p0'):
  15. *** bash-5.0-patched/subst.c 2019-08-29 11:16:49.000000000 -0400
  16. --- b/subst.c 2020-04-02 16:24:19.000000000 -0400
  17. ***************
  18. *** 5337,5341 ****
  19. }
  20. ! char *
  21. copy_fifo_list (sizep)
  22. int *sizep;
  23. --- b/5337,5341 ----
  24. }
  25. ! void *
  26. copy_fifo_list (sizep)
  27. int *sizep;
  28. ***************
  29. *** 5343,5347 ****
  30. if (sizep)
  31. *sizep = 0;
  32. ! return (char *)NULL;
  33. }
  34. --- b/5343,5347 ----
  35. if (sizep)
  36. *sizep = 0;
  37. ! return (void *)NULL;
  38. }
  39. ***************
  40. *** 5409,5414 ****
  41. if (fifo_list[i].file)
  42. {
  43. ! fifo_list[j].file = fifo_list[i].file;
  44. ! fifo_list[j].proc = fifo_list[i].proc;
  45. j++;
  46. }
  47. --- b/5409,5419 ----
  48. if (fifo_list[i].file)
  49. {
  50. ! if (i != j)
  51. ! {
  52. ! fifo_list[j].file = fifo_list[i].file;
  53. ! fifo_list[j].proc = fifo_list[i].proc;
  54. ! fifo_list[i].file = (char *)NULL;
  55. ! fifo_list[i].proc = 0;
  56. ! }
  57. j++;
  58. }
  59. ***************
  60. *** 5426,5433 ****
  61. void
  62. close_new_fifos (list, lsize)
  63. ! char *list;
  64. int lsize;
  65. {
  66. int i;
  67. if (list == 0)
  68. --- b/5431,5439 ----
  69. void
  70. close_new_fifos (list, lsize)
  71. ! void *list;
  72. int lsize;
  73. {
  74. int i;
  75. + char *plist;
  76. if (list == 0)
  77. ***************
  78. *** 5437,5442 ****
  79. }
  80. ! for (i = 0; i < lsize; i++)
  81. ! if (list[i] == 0 && i < fifo_list_size && fifo_list[i].proc != -1)
  82. unlink_fifo (i);
  83. --- b/5443,5448 ----
  84. }
  85. ! for (plist = (char *)list, i = 0; i < lsize; i++)
  86. ! if (plist[i] == 0 && i < fifo_list_size && fifo_list[i].proc != -1)
  87. unlink_fifo (i);
  88. ***************
  89. *** 5560,5568 ****
  90. }
  91. ! char *
  92. copy_fifo_list (sizep)
  93. int *sizep;
  94. {
  95. ! char *ret;
  96. if (nfds == 0 || totfds == 0)
  97. --- b/5566,5574 ----
  98. }
  99. ! void *
  100. copy_fifo_list (sizep)
  101. int *sizep;
  102. {
  103. ! void *ret;
  104. if (nfds == 0 || totfds == 0)
  105. ***************
  106. *** 5570,5579 ****
  107. if (sizep)
  108. *sizep = 0;
  109. ! return (char *)NULL;
  110. }
  111. if (sizep)
  112. *sizep = totfds;
  113. ! ret = (char *)xmalloc (totfds * sizeof (pid_t));
  114. return (memcpy (ret, dev_fd_list, totfds * sizeof (pid_t)));
  115. }
  116. --- b/5576,5585 ----
  117. if (sizep)
  118. *sizep = 0;
  119. ! return (void *)NULL;
  120. }
  121. if (sizep)
  122. *sizep = totfds;
  123. ! ret = xmalloc (totfds * sizeof (pid_t));
  124. return (memcpy (ret, dev_fd_list, totfds * sizeof (pid_t)));
  125. }
  126. ***************
  127. *** 5648,5655 ****
  128. void
  129. close_new_fifos (list, lsize)
  130. ! char *list;
  131. int lsize;
  132. {
  133. int i;
  134. if (list == 0)
  135. --- b/5654,5662 ----
  136. void
  137. close_new_fifos (list, lsize)
  138. ! void *list;
  139. int lsize;
  140. {
  141. int i;
  142. + pid_t *plist;
  143. if (list == 0)
  144. ***************
  145. *** 5659,5664 ****
  146. }
  147. ! for (i = 0; i < lsize; i++)
  148. ! if (list[i] == 0 && i < totfds && dev_fd_list[i])
  149. unlink_fifo (i);
  150. --- b/5666,5671 ----
  151. }
  152. ! for (plist = (pid_t *)list, i = 0; i < lsize; i++)
  153. ! if (plist[i] == 0 && i < totfds && dev_fd_list[i])
  154. unlink_fifo (i);
  155. *** bash-5.0-patched/subst.h 2018-10-21 18:46:09.000000000 -0400
  156. --- b/subst.h 2020-04-02 16:29:28.000000000 -0400
  157. ***************
  158. *** 274,280 ****
  159. extern void unlink_fifo __P((int));
  160. ! extern char *copy_fifo_list __P((int *));
  161. ! extern void unlink_new_fifos __P((char *, int));
  162. ! extern void close_new_fifos __P((char *, int));
  163. extern void clear_fifo_list __P((void));
  164. --- b/274,279 ----
  165. extern void unlink_fifo __P((int));
  166. ! extern void *copy_fifo_list __P((int *));
  167. ! extern void close_new_fifos __P((void *, int));
  168. extern void clear_fifo_list __P((void));
  169. *** bash-5.0-patched/execute_cmd.c 2020-02-06 20:16:48.000000000 -0500
  170. --- b/execute_cmd.c 2020-04-02 17:00:10.000000000 -0400
  171. ***************
  172. *** 565,569 ****
  173. #if defined (PROCESS_SUBSTITUTION)
  174. volatile int ofifo, nfifo, osize, saved_fifo;
  175. ! volatile char *ofifo_list;
  176. #endif
  177. --- b/565,569 ----
  178. #if defined (PROCESS_SUBSTITUTION)
  179. volatile int ofifo, nfifo, osize, saved_fifo;
  180. ! volatile void *ofifo_list;
  181. #endif
  182. ***************
  183. *** 751,760 ****
  184. # endif
  185. ! if (variable_context != 0) /* XXX - also if sourcelevel != 0? */
  186. {
  187. ofifo = num_fifos ();
  188. ofifo_list = copy_fifo_list ((int *)&osize);
  189. begin_unwind_frame ("internal_fifos");
  190. ! add_unwind_protect (xfree, ofifo_list);
  191. saved_fifo = 1;
  192. }
  193. --- b/751,762 ----
  194. # endif
  195. ! /* XXX - also if sourcelevel != 0? */
  196. ! if (variable_context != 0)
  197. {
  198. ofifo = num_fifos ();
  199. ofifo_list = copy_fifo_list ((int *)&osize);
  200. begin_unwind_frame ("internal_fifos");
  201. ! if (ofifo_list)
  202. ! add_unwind_protect (xfree, ofifo_list);
  203. saved_fifo = 1;
  204. }
  205. ***************
  206. *** 1100,1123 ****
  207. nfifo = num_fifos ();
  208. if (nfifo > ofifo)
  209. ! close_new_fifos ((char *)ofifo_list, osize);
  210. free ((void *)ofifo_list);
  211. discard_unwind_frame ("internal_fifos");
  212. }
  213. - # if defined (HAVE_DEV_FD)
  214. - /* Reap process substitutions at the end of loops */
  215. - switch (command->type)
  216. - {
  217. - case cm_while:
  218. - case cm_until:
  219. - case cm_for:
  220. - case cm_group:
  221. - # if defined (ARITH_FOR_COMMAND)
  222. - case cm_arith_for:
  223. - # endif
  224. - reap_procsubs ();
  225. - default:
  226. - break;
  227. - }
  228. - # endif /* HAVE_DEV_FD */
  229. #endif
  230. --- b/1102,1109 ----
  231. nfifo = num_fifos ();
  232. if (nfifo > ofifo)
  233. ! close_new_fifos ((void *)ofifo_list, osize);
  234. free ((void *)ofifo_list);
  235. discard_unwind_frame ("internal_fifos");
  236. }
  237. #endif
  238. *** bash-5.0/patchlevel.h 2016-06-22 14:51:03.000000000 -0400
  239. --- b/patchlevel.h 2016-10-01 11:01:28.000000000 -0400
  240. ***************
  241. *** 26,30 ****
  242. looks for to find the patch level (for the sccs version string). */
  243. ! #define PATCHLEVEL 16
  244. #endif /* _PATCHLEVEL_H_ */
  245. --- b/26,30 ----
  246. looks for to find the patch level (for the sccs version string). */
  247. ! #define PATCHLEVEL 17
  248. #endif /* _PATCHLEVEL_H_ */