58 + |
58 + |
59 + sp = shp->sftable[f2]; |
59 + sp = shp->sftable[f2]; |
60 if(f1!=f2) |
60 if(f1!=f2) |
61 { |
61 { |
62 /* see whether file descriptor is in use */ |
62 /* see whether file descriptor is in use */ |
63 @@ -672,8 +679,7 @@ int sh_iorenumber(Shell_t *shp, register |
63 @@ -663,8 +670,7 @@ int sh_iorenumber(Shell_t *shp, register |
64 if(f2<=2) |
64 if(f2<=2) |
65 sfset(sp,SF_SHARE|SF_PUBLIC,1); |
65 sfset(sp,SF_SHARE|SF_PUBLIC,1); |
66 } |
66 } |
67 - if(f2>=shp->gd->lim.open_max) |
67 - if(f2>=shp->gd->lim.open_max) |
68 - sh_iovalidfd(shp,f2); |
68 - sh_iovalidfd(shp,f2); |
69 + VALIDATE_FD(shp, f2); |
69 + VALIDATE_FD(shp, f2); |
70 return(f2); |
70 return(f2); |
71 } |
71 } |
72 |
72 |
73 @@ -687,8 +693,9 @@ int sh_close(register int fd) |
73 @@ -678,8 +684,9 @@ int sh_close(register int fd) |
74 register int r = 0; |
74 register int r = 0; |
75 if(fd<0) |
75 if(fd<0) |
76 return(-1); |
76 return(-1); |
77 - if(fd >= shp->gd->lim.open_max) |
77 - if(fd >= shp->gd->lim.open_max) |
78 - sh_iovalidfd(shp,fd); |
78 - sh_iovalidfd(shp,fd); |
79 + |
79 + |
80 + VALIDATE_FD(shp, fd); |
80 + VALIDATE_FD(shp, fd); |
81 + |
81 + |
82 if(!(sp=shp->sftable[fd]) || sfclose(sp) < 0) |
82 if(!(sp=shp->sftable[fd]) || sfclose(sp) < 0) |
83 { |
83 { |
84 int err=errno; |
84 if(fdnotify) |
85 @@ -846,8 +853,7 @@ int sh_open(register const char *path, i |
85 @@ -835,6 +842,9 @@ int sh_open(register const char *path, i |
86 mode = (IOREAD|IOWRITE); |
86 mode = (IOREAD|IOWRITE); |
87 else |
87 else |
88 mode = IOREAD; |
88 mode = IOREAD; |
89 - if(fd >= shp->gd->lim.open_max) |
89 + |
90 - sh_iovalidfd(shp,fd); |
90 + VALIDATE_FD(shp, fd); |
91 + VALIDATE_FD(shp, fd); |
91 + |
92 shp->fdstatus[fd] = mode; |
92 shp->fdstatus[fd] = mode; |
93 return(fd); |
93 return(fd); |
94 } |
94 } |
95 @@ -876,6 +882,8 @@ int sh_iomovefd(register int fdold) |
95 @@ -861,6 +871,8 @@ int sh_iomovefd(register int fdold) |
96 if(fdold<0 || fdold>2) |
96 if(fdold<0 || fdold>2) |
97 return(fdold); |
97 return(fdold); |
98 fdnew = sh_iomovefd(dup(fdold)); |
98 fdnew = sh_iomovefd(dup(fdold)); |
99 + VALIDATE_FD(shp, fdold); |
99 + VALIDATE_FD(shp, fdold); |
100 + VALIDATE_FD(shp, fdnew); |
100 + VALIDATE_FD(shp, fdnew); |
101 shp->fdstatus[fdnew] = (shp->fdstatus[fdold]&~IOCLEX); |
101 shp->fdstatus[fdnew] = (shp->fdstatus[fdold]&~IOCLEX); |
102 close(fdold); |
102 close(fdold); |
103 shp->fdstatus[fdold] = IOCLOSE; |
103 shp->fdstatus[fdold] = IOCLOSE; |
104 @@ -936,6 +944,9 @@ int sh_pipe(register int pv[]) |
104 @@ -897,6 +909,9 @@ int sh_pipe(register int pv[]) |
105 sh_close(fd); |
105 sh_close(fd); |
106 else |
106 else |
107 pv[out] = sh_iomovefd(fd); |
107 pv[out] = sh_iomovefd(fd); |
108 + |
108 + |
109 + VALIDATE_FD(shp, pv[out]); |
109 + VALIDATE_FD(shp, pv[out]); |
110 + |
110 + |
111 if(fcntl(pv[out],F_SETFD,FD_CLOEXEC) >=0) |
111 if(fcntl(pv[out],F_SETFD,FD_CLOEXEC) >=0) |
112 shp->fdstatus[pv[out]] |= IOCLEX; |
112 shp->fdstatus[pv[out]] |= IOCLEX; |
113 shp->fdstatus[pv[out]] = (out?IOWRITE:IOREAD); |
113 shp->fdstatus[pv[out]] = (out?IOWRITE:IOREAD); |
114 @@ -968,6 +979,9 @@ int sh_pipe(register int pv[]) |
114 @@ -929,6 +944,9 @@ int sh_pipe(register int pv[]) |
115 errormsg(SH_DICT,ERROR_system(1),e_pipe); |
115 errormsg(SH_DICT,ERROR_system(1),e_pipe); |
116 } |
116 } |
117 fcntl(pv[out],F_SETFD,FD_CLOEXEC); |
117 fcntl(pv[out],F_SETFD,FD_CLOEXEC); |
118 + |
118 + |
119 + VALIDATE_FD(shp, pv[out]); |
119 + VALIDATE_FD(shp, pv[out]); |
120 + |
120 + |
121 shp->fdstatus[pv[out]] |= IOCLEX; |
121 shp->fdstatus[pv[out]] |= IOCLEX; |
122 pv[1-out] = -1; |
122 pv[1-out] = -1; |
123 pv[2] = port; |
123 pv[2] = port; |
124 @@ -997,9 +1011,13 @@ static int pat_line(const regex_t* rp, c |
124 @@ -958,9 +976,13 @@ static int pat_line(const regex_t* rp, c |
125 static int io_patseek(Shell_t *shp, regex_t *rp, Sfio_t* sp, int flags) |
125 static int io_patseek(Shell_t *shp, regex_t *rp, Sfio_t* sp, int flags) |
126 { |
126 { |
127 char *cp, *match; |
127 char *cp, *match; |
128 - int r, fd=sffileno(sp), close_exec = shp->fdstatus[fd]&IOCLEX; |
128 - int r, fd=sffileno(sp), close_exec = shp->fdstatus[fd]&IOCLEX; |
129 + int r, fd, close_exec; |
129 + int r, fd, close_exec; |
252 savefd = filemap[fd].save_fd; |
252 savefd = filemap[fd].save_fd; |
253 + VALIDATE_FD(shp, savefd); |
253 + VALIDATE_FD(shp, savefd); |
254 shp->sftable[savefd] = 0; |
254 shp->sftable[savefd] = 0; |
255 sh_close(savefd); |
255 sh_close(savefd); |
256 return; |
256 return; |
257 @@ -1778,6 +1815,7 @@ void sh_iorestore(Shell_t *shp, int last |
257 @@ -1699,6 +1740,7 @@ void sh_iorestore(Shell_t *shp, int last |
258 sh_close(origfd); |
258 sh_close(origfd); |
259 if ((savefd = filemap[fd].save_fd) >= 0) |
259 if ((savefd = filemap[fd].save_fd) >= 0) |
260 { |
260 { |
261 + VALIDATE_FD(shp, savefd); |
261 + VALIDATE_FD(shp, savefd); |
262 sh_fcntl(savefd, F_DUPFD, origfd); |
262 sh_fcntl(savefd, F_DUPFD, origfd); |
263 if(savefd==job.fd) |
263 if(savefd==job.fd) |
264 job.fd=origfd; |
264 job.fd=origfd; |
265 @@ -2035,6 +2073,9 @@ static ssize_t slowread(Sfio_t *iop,void |
265 @@ -1954,6 +1996,9 @@ static ssize_t slowread(Sfio_t *iop,void |
266 int sh_iocheckfd(Shell_t *shp, register int fd) |
266 int sh_iocheckfd(Shell_t *shp, register int fd) |
267 { |
267 { |
268 register int flags, n; |
268 register int flags, n; |
269 + |
269 + |
270 + VALIDATE_FD(shp, fd); |
270 + VALIDATE_FD(shp, fd); |
271 + |
271 + |
272 if((n=shp->fdstatus[fd])&IOCLOSE) |
272 if((n=shp->fdstatus[fd])&IOCLOSE) |
273 return(n); |
273 return(n); |
274 if(!(n&(IOREAD|IOWRITE))) |
274 if(!(n&(IOREAD|IOWRITE))) |
275 @@ -2226,7 +2267,7 @@ static void sftrack(Sfio_t* sp, int flag |
275 @@ -2145,7 +2190,7 @@ static void sftrack(Sfio_t* sp, int flag |
276 return; |
276 return; |
277 } |
277 } |
278 #endif |
278 #endif |
279 - if(fd<0 || fd==PSEUDOFD || (fd>=shp->gd->lim.open_max && !sh_iovalidfd(shp,fd))) |
279 - if(fd<0 || (fd>=shp->gd->lim.open_max && !sh_iovalidfd(shp,fd))) |
280 + if(fd<0 || fd==PSEUDOFD || !VALIDATE_FD(shp, fd)) |
280 + if (fd < 0 || !VALIDATE_FD(shp, fd)) |
281 return; |
281 return; |
282 if(sh_isstate(SH_NOTRACK)) |
282 if(sh_isstate(SH_NOTRACK)) |
283 return; |
283 return; |
284 @@ -2495,6 +2536,8 @@ ssize_t sh_read(register int fd, void* b |
284 @@ -2413,6 +2458,8 @@ ssize_t sh_read(register int fd, void* b |
285 { |
285 { |
286 Shell_t *shp = sh_getinterp(); |
286 Shell_t *shp = sh_getinterp(); |
287 register Sfio_t *sp; |
287 register Sfio_t *sp; |
288 + |
288 + |
289 + VALIDATE_FD(shp, fd); |
289 + VALIDATE_FD(shp, fd); |
290 if(sp=shp->sftable[fd]) |
290 if(sp=shp->sftable[fd]) |
291 return(sfread(sp,buff,n)); |
291 return(sfread(sp,buff,n)); |
292 else |
292 else |
293 @@ -2509,6 +2552,8 @@ ssize_t sh_write(register int fd, const |
293 @@ -2427,6 +2474,8 @@ ssize_t sh_write(register int fd, const |
294 { |
294 { |
295 Shell_t *shp = sh_getinterp(); |
295 Shell_t *shp = sh_getinterp(); |
296 register Sfio_t *sp; |
296 register Sfio_t *sp; |
297 + |
297 + |
298 + VALIDATE_FD(shp, fd); |
298 + VALIDATE_FD(shp, fd); |
299 if(sp=shp->sftable[fd]) |
299 if(sp=shp->sftable[fd]) |
300 return(sfwrite(sp,buff,n)); |
300 return(sfwrite(sp,buff,n)); |
301 else |
301 else |
302 @@ -2523,6 +2568,8 @@ off_t sh_seek(register int fd, off_t off |
302 @@ -2441,6 +2490,8 @@ off_t sh_seek(register int fd, off_t off |
303 { |
303 { |
304 Shell_t *shp = sh_getinterp(); |
304 Shell_t *shp = sh_getinterp(); |
305 register Sfio_t *sp; |
305 register Sfio_t *sp; |
306 + |
306 + |
307 + VALIDATE_FD(shp, fd); |
307 + VALIDATE_FD(shp, fd); |
308 if((sp=shp->sftable[fd]) && (sfset(sp,0,0)&(SF_READ|SF_WRITE))) |
308 if((sp=shp->sftable[fd]) && (sfset(sp,0,0)&(SF_READ|SF_WRITE))) |
309 return(sfseek(sp,offset,whence)); |
309 return(sfseek(sp,offset,whence)); |
310 else |
310 else |
311 @@ -2534,6 +2581,9 @@ int sh_dup(register int old) |
311 @@ -2452,6 +2503,9 @@ int sh_dup(register int old) |
312 { |
312 { |
313 Shell_t *shp = sh_getinterp(); |
313 Shell_t *shp = sh_getinterp(); |
314 register int fd = dup(old); |
314 register int fd = dup(old); |
315 + |
315 + |
316 + VALIDATE_FD(shp, old); |
316 + VALIDATE_FD(shp, old); |
317 + VALIDATE_FD(shp, fd); |
317 + VALIDATE_FD(shp, fd); |
318 if(fd>=0) |
318 if(fd>=0) |
319 { |
319 { |
320 if(shp->fdstatus[old] == IOCLOSE) |
320 if(shp->fdstatus[old] == IOCLOSE) |
321 @@ -2555,13 +2605,15 @@ int sh_fcntl(register int fd, int op, .. |
321 @@ -2473,13 +2527,15 @@ int sh_fcntl(register int fd, int op, .. |
322 arg = va_arg(ap, int) ; |
322 arg = va_arg(ap, int) ; |
323 va_end(ap); |
323 va_end(ap); |
324 newfd = fcntl(fd,op,arg); |
324 newfd = fcntl(fd,op,arg); |
325 + |
325 + |
326 + VALIDATE_FD(shp, fd); |
326 + VALIDATE_FD(shp, fd); |
354 + VALIDATE_FD(shp, fd); |
354 + VALIDATE_FD(shp, fd); |
355 + sp = shp->sftable[fd]; |
355 + sp = shp->sftable[fd]; |
356 if(!sp && (status = sh_iocheckfd(shp,fd))!=IOCLOSE) |
356 if(!sp && (status = sh_iocheckfd(shp,fd))!=IOCLOSE) |
357 { |
357 { |
358 register int flags=0; |
358 register int flags=0; |
359 --- INIT.2012-08-01.old/src/cmd/ksh93/sh/lex.c 2015-02-24 13:25:19.370183959 -0800 |
359 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/lex.c INIT.2011-02-08/src/cmd/ksh93/sh/lex.c |
360 +++ INIT.2012-08-01/src/cmd/ksh93/sh/lex.c 2015-03-04 13:27:49.211457345 -0800 |
360 --- INIT.2011-02-08.clean/src/cmd/ksh93/sh/lex.c 2012-05-02 03:16:17.388010187 -0700 |
|
361 +++ INIT.2011-02-08/src/cmd/ksh93/sh/lex.c 2012-05-02 03:17:53.567785551 -0700 |
361 @@ -25,6 +25,9 @@ |
362 @@ -25,6 +25,9 @@ |
362 * AT&T Labs |
363 * AT&T Labs |
363 * |
364 * |
364 */ |
365 */ |
365 +/* |
366 +/* |
366 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
367 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
367 + */ |
368 + */ |
368 |
369 |
369 #include <ast.h> |
370 #include <ast.h> |
370 #include <stak.h> |
371 #include <stak.h> |
371 @@ -2122,6 +2125,7 @@ void sh_syntax(Lex_t *lp) |
372 @@ -2053,6 +2056,7 @@ void sh_syntax(Lex_t *lp) |
372 else |
373 else |
373 lp->lastline = shp->inlineno; |
374 lp->lastline = shp->inlineno; |
374 tokstr = fmttoken(lp,tok,tokbuf); |
375 tokstr = fmttoken(lp,tok,tokbuf); |
375 + VALIDATE_FD(shp, shp->infd); |
376 + VALIDATE_FD(shp, shp->infd); |
376 if((sp=fcfile()) || (shp->infd>=0 && (sp=shp->sftable[shp->infd]))) |
377 if((sp=fcfile()) || (shp->infd>=0 && (sp=shp->sftable[shp->infd]))) |
377 { |
378 { |
378 /* clear out any pending input */ |
379 /* clear out any pending input */ |
379 --- INIT.2012-08-01.old/src/cmd/ksh93/sh/macro.c 2015-02-24 13:25:19.363200741 -0800 |
380 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/macro.c INIT.2011-02-08/src/cmd/ksh93/sh/macro.c |
380 +++ INIT.2012-08-01/src/cmd/ksh93/sh/macro.c 2015-03-04 13:27:49.212566247 -0800 |
381 --- INIT.2011-02-08.clean/src/cmd/ksh93/sh/macro.c 2012-05-02 03:16:26.100861446 -0700 |
381 @@ -2121,6 +2121,7 @@ static void comsubst(Mac_t *mp,register |
382 +++ INIT.2011-02-08/src/cmd/ksh93/sh/macro.c 2012-05-02 03:17:53.569195199 -0700 |
|
383 @@ -2086,6 +2086,7 @@ static void comsubst(Mac_t *mp,register |
382 sh_popcontext(mp->shp,&buff); |
384 sh_popcontext(mp->shp,&buff); |
383 if(r==0 && ip && (ip->iofile&IOLSEEK)) |
385 if(r==0 && ip && (ip->iofile&IOLSEEK)) |
384 { |
386 { |
385 + VALIDATE_FD(mp->shp, fd); |
387 + VALIDATE_FD(mp->shp, fd); |
386 if(sp=mp->shp->sftable[fd]) |
388 if(sp=mp->shp->sftable[fd]) |
387 num = sftell(sp); |
389 num = sftell(sp); |
388 else |
390 else |
389 --- INIT.2012-08-01.old/src/cmd/ksh93/sh/main.c 2015-02-24 13:25:19.364162232 -0800 |
391 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/main.c INIT.2011-02-08/src/cmd/ksh93/sh/main.c |
390 +++ INIT.2012-08-01/src/cmd/ksh93/sh/main.c 2015-03-04 13:27:49.213386462 -0800 |
392 --- INIT.2011-02-08.clean/src/cmd/ksh93/sh/main.c 2012-05-02 03:16:17.389138504 -0700 |
|
393 +++ INIT.2011-02-08/src/cmd/ksh93/sh/main.c 2012-05-02 03:17:53.570027033 -0700 |
391 @@ -26,6 +26,9 @@ |
394 @@ -26,6 +26,9 @@ |
392 * AT&T Labs |
395 * AT&T Labs |
393 * |
396 * |
394 */ |
397 */ |
395 +/* |
398 +/* |
396 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
399 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
397 + */ |
400 + */ |
398 |
401 |
399 #include <ast.h> |
402 #include <ast.h> |
400 #include <sfio.h> |
403 #include <sfio.h> |
401 @@ -376,8 +379,10 @@ static void exfile(register Shell_t *shp |
404 @@ -396,8 +399,10 @@ static void exfile(register Shell_t *shp |
402 if(fno > 0) |
405 if(fno > 0) |
403 { |
406 { |
404 int r; |
407 int r; |
405 + VALIDATE_FD(shp, fno); |
408 + VALIDATE_FD(shp, fno); |
406 if(fno < 10 && ((r=sh_fcntl(fno,F_DUPFD,10))>=10)) |
409 if(fno < 10 && ((r=sh_fcntl(fno,F_DUPFD,10))>=10)) |
407 { |
410 { |
408 + VALIDATE_FD(shp, r); |
411 + VALIDATE_FD(shp, r); |
409 shp->fdstatus[r] = shp->fdstatus[fno]; |
412 shp->fdstatus[r] = shp->fdstatus[fno]; |
410 sh_close(fno); |
413 sh_close(fno); |
411 fno = r; |
414 fno = r; |
412 --- INIT.2012-08-01.old/src/cmd/ksh93/sh/path.c 2015-02-24 13:25:19.360898415 -0800 |
415 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/path.c INIT.2011-02-08/src/cmd/ksh93/sh/path.c |
413 +++ INIT.2012-08-01/src/cmd/ksh93/sh/path.c 2015-03-04 13:27:49.214381188 -0800 |
416 --- INIT.2011-02-08.clean/src/cmd/ksh93/sh/path.c 2012-05-02 03:16:20.752378905 -0700 |
|
417 +++ INIT.2011-02-08/src/cmd/ksh93/sh/path.c 2012-05-02 03:17:53.571078341 -0700 |
414 @@ -23,6 +23,9 @@ |
418 @@ -23,6 +23,9 @@ |
415 * AT&T Labs |
419 * AT&T Labs |
416 * |
420 * |
417 */ |
421 */ |
418 +/* |
422 +/* |
419 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
423 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
420 + */ |
424 + */ |
421 |
425 |
422 #include "defs.h" |
426 #include "defs.h" |
423 #include <fcin.h> |
427 #include <fcin.h> |
424 @@ -1272,6 +1275,7 @@ static void exscript(Shell_t *shp,regist |
428 @@ -1239,6 +1242,7 @@ static void exscript(Shell_t *shp,regist |
425 if(sp=fcfile()) |
429 if(sp=fcfile()) |
426 while(sfstack(sp,SF_POPSTACK)); |
430 while(sfstack(sp,SF_POPSTACK)); |
427 job_clear(); |
431 job_clear(); |
428 + VALIDATE_FD(shp, shp->infd); |
432 + VALIDATE_FD(shp, shp->infd); |
429 if(shp->infd>0 && (shp->fdstatus[shp->infd]&IOCLEX)) |
433 if(shp->infd>0 && (shp->fdstatus[shp->infd]&IOCLEX)) |
430 sh_close(shp->infd); |
434 sh_close(shp->infd); |
431 sh_setstate(sh_state(SH_FORKED)); |
435 sh_setstate(sh_state(SH_FORKED)); |
432 --- INIT.2012-08-01.old/src/cmd/ksh93/sh/subshell.c 2015-02-24 13:25:19.363479570 -0800 |
436 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/subshell.c INIT.2011-02-08/src/cmd/ksh93/sh/subshell.c |
433 +++ INIT.2012-08-01/src/cmd/ksh93/sh/subshell.c 2015-03-04 14:05:03.665801329 -0800 |
437 --- INIT.2011-02-08.clean/src/cmd/ksh93/sh/subshell.c 2012-05-02 03:16:25.241021529 -0700 |
434 @@ -125,6 +125,7 @@ void sh_subtmpfile(Shell_t *shp) |
438 +++ INIT.2011-02-08/src/cmd/ksh93/sh/subshell.c 2012-05-02 03:17:53.571942019 -0700 |
|
439 @@ -115,6 +115,7 @@ void sh_subtmpfile(Shell_t *shp) |
435 if((sp->tmpfd = fd = fcntl(1,F_DUPFD,10)) >= 0) |
440 if((sp->tmpfd = fd = fcntl(1,F_DUPFD,10)) >= 0) |
436 { |
441 { |
437 fcntl(fd,F_SETFD,FD_CLOEXEC); |
442 fcntl(fd,F_SETFD,FD_CLOEXEC); |
438 + VALIDATE_FD(shp, fd); |
443 + VALIDATE_FD(shp, fd); |
439 shp->fdstatus[fd] = shp->fdstatus[1]|IOCLEX; |
444 shp->fdstatus[fd] = shp->fdstatus[1]|IOCLEX; |
440 close(1); |
445 close(1); |
441 } |
446 } |
442 @@ -151,6 +152,7 @@ void sh_subtmpfile(Shell_t *shp) |
447 @@ -141,6 +142,7 @@ void sh_subtmpfile(Shell_t *shp) |
443 } |
448 } |
444 else |
449 else |
445 { |
450 { |
446 + VALIDATE_FD(shp, fd); |
451 + VALIDATE_FD(shp, fd); |
447 shp->fdstatus[fd] = IOREAD|IOWRITE; |
452 shp->fdstatus[fd] = IOREAD|IOWRITE; |
448 sfsync(sfstdout); |
453 sfsync(sfstdout); |
449 if(fd==1) |
454 if(fd==1) |
450 @@ -679,8 +681,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ |
455 @@ -627,6 +629,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ |
451 ((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT; |
456 ((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT; |
452 errormsg(SH_DICT,ERROR_system(1),e_toomany); |
457 errormsg(SH_DICT,ERROR_system(1),e_toomany); |
453 } |
458 } |
454 - if(fd >= shp->gd->lim.open_max) |
|
455 - sh_iovalidfd(shp,fd); |
|
456 + VALIDATE_FD(shp, fd); |
459 + VALIDATE_FD(shp, fd); |
457 shp->sftable[fd] = iop; |
460 shp->sftable[fd] = iop; |
458 fcntl(fd,F_SETFD,FD_CLOEXEC); |
461 fcntl(fd,F_SETFD,FD_CLOEXEC); |
459 shp->fdstatus[fd] = (shp->fdstatus[1]|IOCLEX); |
462 shp->fdstatus[fd] = (shp->fdstatus[1]|IOCLEX); |
460 --- INIT.2012-08-01.old/src/cmd/ksh93/sh/xec.c 2015-02-24 13:25:19.365424099 -0800 |
463 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/xec.c INIT.2011-02-08/src/cmd/ksh93/sh/xec.c |
461 +++ INIT.2012-08-01/src/cmd/ksh93/sh/xec.c 2015-03-04 14:05:12.823587666 -0800 |
464 --- INIT.2011-02-08.clean/src/cmd/ksh93/sh/xec.c 2012-05-02 03:16:17.393286735 -0700 |
462 @@ -117,6 +117,8 @@ static int iousepipe(Shell_t *shp) |
465 +++ INIT.2011-02-08/src/cmd/ksh93/sh/xec.c 2012-05-02 03:17:53.574535124 -0700 |
|
466 @@ -94,6 +94,8 @@ static void iousepipe(Shell_t *shp) |
463 usepipe++; |
467 usepipe++; |
464 fcntl(subpipe[0],F_SETFD,FD_CLOEXEC); |
468 fcntl(subpipe[0],F_SETFD,FD_CLOEXEC); |
465 subpipe[2] = fcntl(1,F_DUPFD,10); |
469 subpipe[2] = fcntl(1,F_DUPFD,10); |
466 + VALIDATE_FD(shp, subpipe[1]); |
470 + VALIDATE_FD(shp, subpipe[1]); |
467 + VALIDATE_FD(shp, subpipe[2]); |
471 + VALIDATE_FD(shp, subpipe[2]); |
468 fcntl(subpipe[2],F_SETFD,FD_CLOEXEC); |
|
469 shp->fdstatus[subpipe[2]] = shp->fdstatus[1]; |
472 shp->fdstatus[subpipe[2]] = shp->fdstatus[1]; |
470 close(1); |
473 close(1); |
471 @@ -141,6 +143,7 @@ static void iounpipe(Shell_t *shp) |
474 fcntl(subpipe[1],F_DUPFD,1); |
472 char buff[SF_BUFSIZE]; |
475 @@ -117,6 +119,7 @@ static void iounpipe(Shell_t *shp) |
|
476 usepipe = 0; |
473 close(1); |
477 close(1); |
474 fcntl(subpipe[2], F_DUPFD, 1); |
478 fcntl(subpipe[2], F_DUPFD, 1); |
475 + VALIDATE_FD(shp, subpipe[2]); |
479 + VALIDATE_FD(shp, subpipe[2]); |
476 shp->fdstatus[1] = shp->fdstatus[subpipe[2]]; |
480 shp->fdstatus[1] = shp->fdstatus[subpipe[2]]; |
477 --usepipe; |
|
478 if(subdup) for(n=0; n < 10; n++) |
481 if(subdup) for(n=0; n < 10; n++) |
479 @@ -886,6 +889,7 @@ static int sh_coexec(Shell_t *shp,const |
482 { |
|
483 @@ -844,6 +847,7 @@ static int sh_coexec(Shell_t *shp,const |
480 if(filt > 2) |
484 if(filt > 2) |
481 { |
485 { |
482 shp->coutpipe = shp->inpipe[1]; |
486 shp->coutpipe = shp->inpipe[1]; |
483 + VALIDATE_FD(shp, shp->coutpipe); |
487 + VALIDATE_FD(shp, shp->coutpipe); |
484 shp->fdptrs[shp->coutpipe] = &shp->coutpipe; |
488 shp->fdptrs[shp->coutpipe] = &shp->coutpipe; |
485 } |
489 } |
486 } |
490 } |
487 @@ -1646,6 +1650,7 @@ int sh_exec(register const Shnode_t *t, |
491 @@ -1487,6 +1491,7 @@ int sh_exec(register const Shnode_t *t, |
488 if(shp->cpipe[0]<0 || shp->cpipe[1] < 0) |
492 if(shp->cpipe[0]<0 || shp->cpipe[1] < 0) |
489 { |
493 { |
490 sh_copipe(shp,shp->outpipe=shp->cpipe,0); |
494 sh_copipe(shp,shp->outpipe=shp->cpipe,0); |
491 + VALIDATE_FD(shp, shp->cpipe[0]); |
495 + VALIDATE_FD(shp, shp->cpipe[0]); |
492 shp->fdptrs[shp->cpipe[0]] = shp->cpipe; |
496 shp->fdptrs[shp->cpipe[0]] = shp->cpipe; |
493 } |
497 } |
494 sh_copipe(shp,shp->inpipe=pipes,0); |
498 sh_copipe(shp,shp->inpipe=pipes,0); |
495 @@ -3623,6 +3628,8 @@ static void coproc_init(Shell_t *shp, in |
499 @@ -3419,6 +3424,8 @@ static void coproc_init(Shell_t *shp, in |
496 if((outfd=shp->cpipe[1]) < 10) |
500 if((outfd=shp->cpipe[1]) < 10) |
497 { |
501 { |
498 int fd=fcntl(shp->cpipe[1],F_DUPFD,10); |
502 int fd=fcntl(shp->cpipe[1],F_DUPFD,10); |
499 + VALIDATE_FD(shp, outfd); |
503 + VALIDATE_FD(shp, outfd); |
500 + VALIDATE_FD(shp, fd); |
504 + VALIDATE_FD(shp, fd); |
501 if(fd>=10) |
505 if(fd>=10) |
502 { |
506 { |
503 shp->fdstatus[fd] = (shp->fdstatus[outfd]&~IOCLEX); |
507 shp->fdstatus[fd] = (shp->fdstatus[outfd]&~IOCLEX); |
504 @@ -3631,6 +3638,9 @@ static void coproc_init(Shell_t *shp, in |
508 @@ -3427,6 +3434,9 @@ static void coproc_init(Shell_t *shp, in |
505 shp->cpipe[1] = fd; |
509 shp->cpipe[1] = fd; |
506 } |
510 } |
507 } |
511 } |
508 + VALIDATE_FD(shp, shp->cpipe[0]); |
512 + VALIDATE_FD(shp, shp->cpipe[0]); |
509 + VALIDATE_FD(shp, shp->cpipe[1]); |
513 + VALIDATE_FD(shp, shp->cpipe[1]); |
510 + |
514 + |
511 if(fcntl(*shp->cpipe,F_SETFD,FD_CLOEXEC)>=0) |
515 if(fcntl(*shp->cpipe,F_SETFD,FD_CLOEXEC)>=0) |
512 shp->fdstatus[shp->cpipe[0]] |= IOCLEX; |
516 shp->fdstatus[shp->cpipe[0]] |= IOCLEX; |
513 shp->fdptrs[shp->cpipe[0]] = shp->cpipe; |
517 shp->fdptrs[shp->cpipe[0]] = shp->cpipe; |
514 @@ -3641,7 +3651,9 @@ static void coproc_init(Shell_t *shp, in |
518 @@ -3437,7 +3447,9 @@ static void coproc_init(Shell_t *shp, in |
515 shp->outpipe = shp->cpipe; |
519 shp->outpipe = shp->cpipe; |
516 sh_pipe(shp->inpipe=pipes); |
520 sh_pipe(shp->inpipe=pipes); |
517 shp->coutpipe = shp->inpipe[1]; |
521 shp->coutpipe = shp->inpipe[1]; |
518 + VALIDATE_FD(shp, shp->coutpipe); |
522 + VALIDATE_FD(shp, shp->coutpipe); |
519 shp->fdptrs[shp->coutpipe] = &shp->coutpipe; |
523 shp->fdptrs[shp->coutpipe] = &shp->coutpipe; |
520 + VALIDATE_FD(shp, shp->outpipe[0]); |
524 + VALIDATE_FD(shp, shp->outpipe[0]); |
521 if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0) |
525 if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0) |
522 shp->fdstatus[shp->outpipe[0]] |= IOCLEX; |
526 shp->fdstatus[shp->outpipe[0]] |= IOCLEX; |
523 } |
527 } |
524 @@ -3812,6 +3824,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons |
528 @@ -3608,6 +3620,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons |
525 int fd = shp->inpipe[1]; |
529 int fd = shp->inpipe[1]; |
526 sh_iosave(shp,0,buffp->topfd,(char*)0); |
530 sh_iosave(shp,0,buff.topfd,(char*)0); |
527 sh_iorenumber(shp,shp->inpipe[0],0); |
531 sh_iorenumber(shp,shp->inpipe[0],0); |
528 + VALIDATE_FD(shp, fd); |
532 + VALIDATE_FD(shp, fd); |
529 if(fd>=0 && (!(otype&FPOU) || (otype&FCOOP)) && fcntl(fd,F_SETFD,FD_CLOEXEC)>=0) |
533 if(fd>=0 && (!(otype&FPOU) || (otype&FCOOP)) && fcntl(fd,F_SETFD,FD_CLOEXEC)>=0) |
530 shp->fdstatus[fd] |= IOCLEX; |
534 shp->fdstatus[fd] |= IOCLEX; |
531 } |
535 } |
532 @@ -3823,6 +3836,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons |
536 @@ -3619,6 +3632,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons |
533 #endif /* SHOPT_COSHELL */ |
537 #endif /* SHOPT_COSHELL */ |
534 sh_iosave(shp,1,buffp->topfd,(char*)0); |
538 sh_iosave(shp,1,buff.topfd,(char*)0); |
535 sh_iorenumber(shp,sh_dup(shp->outpipe[1]),1); |
539 sh_iorenumber(shp,sh_dup(shp->outpipe[1]),1); |
536 + VALIDATE_FD(shp, shp->outpipe[0]); |
540 + VALIDATE_FD(shp, shp->outpipe[0]); |
537 if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0) |
541 if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0) |
538 shp->fdstatus[shp->outpipe[0]] |= IOCLEX; |
542 shp->fdstatus[shp->outpipe[0]] |= IOCLEX; |
539 } |
543 } |
540 @@ -3862,6 +3876,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons |
544 @@ -3658,6 +3672,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons |
541 signal(SIGQUIT,sh_fault); |
545 signal(SIGQUIT,sh_fault); |
542 signal(SIGINT,sh_fault); |
546 signal(SIGINT,sh_fault); |
543 } |
547 } |
544 + VALIDATE_FD(shp, shp->inpipe[1]); |
548 + VALIDATE_FD(shp, shp->inpipe[1]); |
545 if((otype&FPIN) && (!(otype&FPOU) || (otype&FCOOP)) && fcntl(shp->inpipe[1],F_SETFD,FD_CLOEXEC)>=0) |
549 if((otype&FPIN) && (!(otype&FPOU) || (otype&FCOOP)) && fcntl(shp->inpipe[1],F_SETFD,FD_CLOEXEC)>=0) |