aboutsummaryrefslogtreecommitdiff
path: root/package/bash/0017-bash50-017.patch
blob: 6758b203f86ad2641f706bbb55c334b993ffbb0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
From https://ftp.gnu.org/gnu/bash/bash-5.0-patches/bash55-017

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>

			     BASH PATCH REPORT
			     =================

Bash-Release:	5.0
Patch-ID:	bash50-017

Bug-Reported-by:	Valentin Lab <valentin.lab@kalysto.org>
Bug-Reference-ID:	<ab981b9c-60a5-46d0-b7e6-a6d88b80df50@kalysto.org>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2020-03/msg00062.html

Bug-Description:

There were cases where patch 16 reaped process substitution file descriptors
(or FIFOs) and processes to early. This is a better fix for the problem that
bash50-016 attempted to solve.

Patch (apply with `patch -p0'):

*** bash-5.0-patched/subst.c	2019-08-29 11:16:49.000000000 -0400
--- b/subst.c	2020-04-02 16:24:19.000000000 -0400
***************
*** 5337,5341 ****
  }
  
! char *
  copy_fifo_list (sizep)
       int *sizep;
--- b/5337,5341 ----
  }
  
! void *
  copy_fifo_list (sizep)
       int *sizep;
***************
*** 5343,5347 ****
    if (sizep)
      *sizep = 0;
!   return (char *)NULL;
  }
  
--- b/5343,5347 ----
    if (sizep)
      *sizep = 0;
!   return (void *)NULL;
  }
  
***************
*** 5409,5414 ****
  	if (fifo_list[i].file)
  	  {
! 	    fifo_list[j].file = fifo_list[i].file;
! 	    fifo_list[j].proc = fifo_list[i].proc;
  	    j++;
  	  }
--- b/5409,5419 ----
  	if (fifo_list[i].file)
  	  {
! 	    if (i != j)
! 	      {
! 		fifo_list[j].file = fifo_list[i].file;
! 		fifo_list[j].proc = fifo_list[i].proc;
! 		fifo_list[i].file = (char *)NULL;
! 		fifo_list[i].proc = 0;
! 	      }
  	    j++;
  	  }
***************
*** 5426,5433 ****
  void
  close_new_fifos (list, lsize)
!      char *list;
       int lsize;
  {
    int i;
  
    if (list == 0)
--- b/5431,5439 ----
  void
  close_new_fifos (list, lsize)
!      void *list;
       int lsize;
  {
    int i;
+   char *plist;
  
    if (list == 0)
***************
*** 5437,5442 ****
      }
  
!   for (i = 0; i < lsize; i++)
!     if (list[i] == 0 && i < fifo_list_size && fifo_list[i].proc != -1)
        unlink_fifo (i);
  
--- b/5443,5448 ----
      }
  
!   for (plist = (char *)list, i = 0; i < lsize; i++)
!     if (plist[i] == 0 && i < fifo_list_size && fifo_list[i].proc != -1)
        unlink_fifo (i);
  
***************
*** 5560,5568 ****
  }
  
! char *
  copy_fifo_list (sizep)
       int *sizep;
  {
!   char *ret;
  
    if (nfds == 0 || totfds == 0)
--- b/5566,5574 ----
  }
  
! void *
  copy_fifo_list (sizep)
       int *sizep;
  {
!   void *ret;
  
    if (nfds == 0 || totfds == 0)
***************
*** 5570,5579 ****
        if (sizep)
  	*sizep = 0;
!       return (char *)NULL;
      }
  
    if (sizep)
      *sizep = totfds;
!   ret = (char *)xmalloc (totfds * sizeof (pid_t));
    return (memcpy (ret, dev_fd_list, totfds * sizeof (pid_t)));
  }
--- b/5576,5585 ----
        if (sizep)
  	*sizep = 0;
!       return (void *)NULL;
      }
  
    if (sizep)
      *sizep = totfds;
!   ret = xmalloc (totfds * sizeof (pid_t));
    return (memcpy (ret, dev_fd_list, totfds * sizeof (pid_t)));
  }
***************
*** 5648,5655 ****
  void
  close_new_fifos (list, lsize)
!      char *list;
       int lsize;
  {
    int i;
  
    if (list == 0)
--- b/5654,5662 ----
  void
  close_new_fifos (list, lsize)
!      void *list;
       int lsize;
  {
    int i;
+   pid_t *plist;
  
    if (list == 0)
***************
*** 5659,5664 ****
      }
  
!   for (i = 0; i < lsize; i++)
!     if (list[i] == 0 && i < totfds && dev_fd_list[i])
        unlink_fifo (i);
  
--- b/5666,5671 ----
      }
  
!   for (plist = (pid_t *)list, i = 0; i < lsize; i++)
!     if (plist[i] == 0 && i < totfds && dev_fd_list[i])
        unlink_fifo (i);
  
*** bash-5.0-patched/subst.h	2018-10-21 18:46:09.000000000 -0400
--- b/subst.h	2020-04-02 16:29:28.000000000 -0400
***************
*** 274,280 ****
  extern void unlink_fifo __P((int));
  
! extern char *copy_fifo_list __P((int *));
! extern void unlink_new_fifos __P((char *, int));
! extern void close_new_fifos __P((char *, int));
  
  extern void clear_fifo_list __P((void));
--- b/274,279 ----
  extern void unlink_fifo __P((int));
  
! extern void *copy_fifo_list __P((int *));
! extern void close_new_fifos __P((void *, int));
  
  extern void clear_fifo_list __P((void));
*** bash-5.0-patched/execute_cmd.c	2020-02-06 20:16:48.000000000 -0500
--- b/execute_cmd.c	2020-04-02 17:00:10.000000000 -0400
***************
*** 565,569 ****
  #if defined (PROCESS_SUBSTITUTION)
    volatile int ofifo, nfifo, osize, saved_fifo;
!   volatile char *ofifo_list;
  #endif
  
--- b/565,569 ----
  #if defined (PROCESS_SUBSTITUTION)
    volatile int ofifo, nfifo, osize, saved_fifo;
!   volatile void *ofifo_list;
  #endif
  
***************
*** 751,760 ****
  #  endif
  
!   if (variable_context != 0)	/* XXX - also if sourcelevel != 0? */
      {
        ofifo = num_fifos ();
        ofifo_list = copy_fifo_list ((int *)&osize);
        begin_unwind_frame ("internal_fifos");
!       add_unwind_protect (xfree, ofifo_list);
        saved_fifo = 1;
      }
--- b/751,762 ----
  #  endif
  
!   /* XXX - also if sourcelevel != 0? */
!   if (variable_context != 0)
      {
        ofifo = num_fifos ();
        ofifo_list = copy_fifo_list ((int *)&osize);
        begin_unwind_frame ("internal_fifos");
!       if (ofifo_list)
! 	add_unwind_protect (xfree, ofifo_list);
        saved_fifo = 1;
      }
***************
*** 1100,1123 ****
        nfifo = num_fifos ();
        if (nfifo > ofifo)
! 	close_new_fifos ((char *)ofifo_list, osize);
        free ((void *)ofifo_list);
        discard_unwind_frame ("internal_fifos");
      }
- # if defined (HAVE_DEV_FD)
-   /* Reap process substitutions at the end of loops */
-   switch (command->type)
-     {
-     case cm_while:
-     case cm_until:
-     case cm_for:
-     case cm_group:
- #    if defined (ARITH_FOR_COMMAND)
-     case cm_arith_for:
- #    endif
-       reap_procsubs ();
-     default:
-       break;
-     }
- #  endif /* HAVE_DEV_FD */
  #endif
  
--- b/1102,1109 ----
        nfifo = num_fifos ();
        if (nfifo > ofifo)
! 	close_new_fifos ((void *)ofifo_list, osize);
        free ((void *)ofifo_list);
        discard_unwind_frame ("internal_fifos");
      }
  #endif
  

*** bash-5.0/patchlevel.h	2016-06-22 14:51:03.000000000 -0400
--- b/patchlevel.h	2016-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 16
  
  #endif /* _PATCHLEVEL_H_ */
--- b/26,30 ----
     looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 17
  
  #endif /* _PATCHLEVEL_H_ */