components/ksh93/patches/100-CR6964621.patch
changeset 4196 d697072a92f5
parent 805 23c55a2f8a8e
child 4268 d723f8ed85fe
equal deleted inserted replaced
4195:d88c5d15a4af 4196:d697072a92f5
       
     1 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/include/io.h INIT.2011-02-08/src/cmd/ksh93/include/io.h
       
     2 --- INIT.2011-02-08.clean/src/cmd/ksh93/include/io.h	2012-05-02 03:16:17.383778774 -0700
       
     3 +++ INIT.2011-02-08/src/cmd/ksh93/include/io.h	2012-05-02 03:17:53.562408338 -0700
       
     4 @@ -23,6 +23,9 @@
       
     5   *	David Korn
       
     6   *
       
     7   */
       
     8 +/*
       
     9 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
       
    10 + */
       
    11  
       
    12  #include	<ast.h>
       
    13  #include	<sfio.h>
       
    14 @@ -84,6 +87,12 @@ extern int	sh_devtofd(const char*);
       
    15  extern int	sh_isdevfd(const char*);
       
    16  extern int	sh_source(Shell_t*, Sfio_t*, const char*);
       
    17  
       
    18 +extern int	VALIDATE_FD(Shell_t *, int);
       
    19 +
       
    20 +#define	VALIDATE_FD(shp, fd) \
       
    21 +	(((fd) >= (shp)->gd->lim.open_max) ? sh_iovalidfd(shp, fd) : 1)
       
    22 +
       
    23 +
       
    24  /* the following are readonly */
       
    25  extern const char	e_pexists[];
       
    26  extern const char	e_query[];
       
    27 @@ -123,4 +132,5 @@ extern const char	e_bash_profile[];
       
    28  extern const char	e_stdprompt[];
       
    29  extern const char	e_supprompt[];
       
    30  extern const char	e_ambiguous[];
       
    31 +
       
    32  #endif /* KSHELL */
       
    33 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/io.c INIT.2011-02-08/src/cmd/ksh93/sh/io.c
       
    34 --- INIT.2011-02-08.clean/src/cmd/ksh93/sh/io.c	2012-05-02 03:16:17.389917698 -0700
       
    35 +++ INIT.2011-02-08/src/cmd/ksh93/sh/io.c	2012-05-02 03:19:12.669621809 -0700
       
    36 @@ -596,8 +596,10 @@ static void io_preserve(Shell_t* shp, re
       
    37  		((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT;
       
    38  		errormsg(SH_DICT,ERROR_system(1),e_toomany);
       
    39  	}
       
    40 -	if(f2 >= shp->gd->lim.open_max)
       
    41 -		sh_iovalidfd(shp,f2);
       
    42 +
       
    43 +	VALIDATE_FD(shp, fd);
       
    44 +	VALIDATE_FD(shp, f2);
       
    45 +
       
    46  	if(shp->fdptrs[fd]=shp->fdptrs[f2])
       
    47  	{
       
    48  		if(f2==job.fd)
       
    49 @@ -623,7 +625,12 @@ static void io_preserve(Shell_t* shp, re
       
    50   */
       
    51  int sh_iorenumber(Shell_t *shp, register int f1,register int f2)
       
    52  {
       
    53 -	register Sfio_t *sp = shp->sftable[f2];
       
    54 +	register Sfio_t *sp;
       
    55 +
       
    56 +	VALIDATE_FD(shp, f1);
       
    57 +	VALIDATE_FD(shp, f2);
       
    58 +
       
    59 +	sp = shp->sftable[f2];
       
    60  	if(f1!=f2)
       
    61  	{
       
    62  		/* see whether file descriptor is in use */
       
    63 @@ -663,8 +670,7 @@ int sh_iorenumber(Shell_t *shp, register
       
    64  		if(f2<=2)
       
    65  			sfset(sp,SF_SHARE|SF_PUBLIC,1);
       
    66  	}
       
    67 -	if(f2>=shp->gd->lim.open_max)
       
    68 -		sh_iovalidfd(shp,f2);
       
    69 +	VALIDATE_FD(shp, f2);
       
    70  	return(f2);
       
    71  }
       
    72  
       
    73 @@ -678,8 +684,9 @@ int sh_close(register int fd)
       
    74  	register int r = 0;
       
    75  	if(fd<0)
       
    76  		return(-1);
       
    77 -	if(fd >= shp->gd->lim.open_max)
       
    78 -		sh_iovalidfd(shp,fd);
       
    79 +
       
    80 +	VALIDATE_FD(shp, fd);
       
    81 +
       
    82  	if(!(sp=shp->sftable[fd]) || sfclose(sp) < 0)
       
    83  	{
       
    84  		if(fdnotify)
       
    85 @@ -835,6 +842,9 @@ int sh_open(register const char *path, i
       
    86  		mode = (IOREAD|IOWRITE);
       
    87  	else
       
    88  		mode = IOREAD;
       
    89 +
       
    90 +	VALIDATE_FD(shp, fd);
       
    91 +
       
    92  	shp->fdstatus[fd] = mode;
       
    93  	return(fd);
       
    94  }
       
    95 @@ -861,6 +871,8 @@ int sh_iomovefd(register int fdold)
       
    96  	if(fdold<0 || fdold>2)
       
    97  		return(fdold);
       
    98  	fdnew = sh_iomovefd(dup(fdold));
       
    99 +	VALIDATE_FD(shp, fdold);
       
   100 +	VALIDATE_FD(shp, fdnew);
       
   101  	shp->fdstatus[fdnew] = (shp->fdstatus[fdold]&~IOCLEX);
       
   102  	close(fdold);
       
   103  	shp->fdstatus[fdold] = IOCLOSE;
       
   104 @@ -897,6 +909,9 @@ int	sh_pipe(register int pv[])
       
   105  		sh_close(fd);
       
   106  	else
       
   107  		pv[out] = sh_iomovefd(fd);
       
   108 +
       
   109 +	VALIDATE_FD(shp, pv[out]);
       
   110 +
       
   111  	if(fcntl(pv[out],F_SETFD,FD_CLOEXEC) >=0)
       
   112  		shp->fdstatus[pv[out]] |= IOCLEX;
       
   113  	shp->fdstatus[pv[out]] = (out?IOWRITE:IOREAD);
       
   114 @@ -929,6 +944,9 @@ int	sh_pipe(register int pv[])
       
   115  		errormsg(SH_DICT,ERROR_system(1),e_pipe);
       
   116  	}
       
   117  	fcntl(pv[out],F_SETFD,FD_CLOEXEC);
       
   118 +
       
   119 +	VALIDATE_FD(shp, pv[out]);
       
   120 +
       
   121  	shp->fdstatus[pv[out]] |= IOCLEX;
       
   122  	pv[1-out] = -1;
       
   123  	pv[2] = port;
       
   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)
       
   126  {
       
   127  	char	*cp, *match;
       
   128 -	int	r, fd=sffileno(sp), close_exec = shp->fdstatus[fd]&IOCLEX;
       
   129 +	int	r, fd, close_exec;
       
   130  	int	was_share,s=(PIPE_BUF>SF_BUFSIZE?SF_BUFSIZE:PIPE_BUF);
       
   131  	size_t	n,m;
       
   132 +
       
   133 +	fd = sffileno(sp);
       
   134 +	VALIDATE_FD(shp, fd);
       
   135 +	close_exec = shp->fdstatus[fd]&IOCLEX;
       
   136  	shp->fdstatus[sffileno(sp)] |= IOCLEX;
       
   137  	if(fd==0)
       
   138  		was_share = sfset(sp,SF_SHARE,1);
       
   139 @@ -994,12 +1016,17 @@ static int io_patseek(Shell_t *shp, rege
       
   140  
       
   141  static Sfoff_t	file_offset(Shell_t *shp, int fn, char *fname)
       
   142  {
       
   143 -	Sfio_t		*sp = shp->sftable[fn];
       
   144 +	Sfio_t		*sp;
       
   145  	char		*cp;
       
   146  	Sfoff_t		off;
       
   147  	struct Eof	endf;
       
   148  	Namval_t	*mp = nv_open("EOF",shp->var_tree,0);
       
   149  	Namval_t	*pp = nv_open("CUR",shp->var_tree,0);
       
   150 +
       
   151 +	VALIDATE_FD(shp, fn);
       
   152 +
       
   153 +	sp = shp->sftable[fn];
       
   154 +
       
   155  	memset(&endf,0,sizeof(struct Eof));
       
   156  	endf.fd = fn;
       
   157  	endf.hdr.disc = &EOF_disc;
       
   158 @@ -1169,7 +1196,7 @@ int	sh_redirect(Shell_t *shp,struct iono
       
   159  			if((iof&IOLSEEK) || ((iof&IOMOV) && *fname=='-'))
       
   160  				fn = nv_getnum(np);
       
   161  		}
       
   162 -		if(fn>=shp->gd->lim.open_max && !sh_iovalidfd(shp,fn))
       
   163 +		if (!VALIDATE_FD(shp, fn))
       
   164  			errormsg(SH_DICT,ERROR_system(1),e_file+4);
       
   165  		if(iof&IOLSEEK)
       
   166  		{
       
   167 @@ -1212,6 +1239,7 @@ int	sh_redirect(Shell_t *shp,struct iono
       
   168  						message = e_file;
       
   169  						goto fail;
       
   170  					}
       
   171 +					VALIDATE_FD(shp, dupfd);
       
   172  					if(shp->subshell && dupfd==1)
       
   173  					{
       
   174  						if(sfset(sfstdout,0,0)&SF_STRING)
       
   175 @@ -1248,8 +1276,7 @@ int	sh_redirect(Shell_t *shp,struct iono
       
   176  					goto traceit;
       
   177  				if((fd=sh_fcntl(dupfd,F_DUPFD,3))<0)
       
   178  					goto fail;
       
   179 -				if(fd>= shp->gd->lim.open_max)
       
   180 -					sh_iovalidfd(shp,fd);
       
   181 +				VALIDATE_FD(shp, fd);
       
   182  				sh_iocheckfd(shp,dupfd);
       
   183  				shp->fdstatus[fd] = (shp->fdstatus[dupfd]&~IOCLEX);
       
   184  				if(toclose<0 && shp->fdstatus[fd]&IOREAD)
       
   185 @@ -1362,7 +1389,11 @@ int	sh_redirect(Shell_t *shp,struct iono
       
   186  			}
       
   187  			if(iof&IOLSEEK)
       
   188  			{
       
   189 -				Sfio_t *sp = shp->sftable[fn];
       
   190 +				Sfio_t *sp;
       
   191 +
       
   192 +				VALIDATE_FD(shp, fn);
       
   193 +
       
   194 +				sp = shp->sftable[fn];
       
   195  				r = shp->fdstatus[fn];
       
   196  				if(!(r&(IOSEEK|IONOSEEK)))
       
   197  					r = sh_iocheckfd(shp,fn);
       
   198 @@ -1443,6 +1474,7 @@ int	sh_redirect(Shell_t *shp,struct iono
       
   199  			}
       
   200  			if(fd<0)
       
   201  			{
       
   202 +				VALIDATE_FD(shp, fn);
       
   203  				if(sh_inuse(shp,fn) || (fn && fn==shp->infd))
       
   204  				{
       
   205  					if(fn>9 || !(shp->inuse_bits&(1<<fn)))
       
   206 @@ -1462,7 +1494,7 @@ int	sh_redirect(Shell_t *shp,struct iono
       
   207  					{
       
   208  						if((fn=fcntl(fd,F_DUPFD,10)) < 0)
       
   209  							goto fail;
       
   210 -						if(fn>=shp->gd->lim.open_max && !sh_iovalidfd(shp,fn))
       
   211 +						if (!VALIDATE_FD(shp, fn))
       
   212  							goto fail;
       
   213  						shp->fdstatus[fn] = shp->fdstatus[fd];
       
   214  						sh_close(fd);
       
   215 @@ -1622,7 +1654,12 @@ void sh_iosave(Shell_t *shp, register in
       
   216  	filemap[shp->topfd++].save_fd = savefd;
       
   217  	if(savefd >=0)
       
   218  	{
       
   219 -		register Sfio_t* sp = shp->sftable[origfd];
       
   220 +		register Sfio_t* sp;
       
   221 +
       
   222 +		VALIDATE_FD(shp, origfd);
       
   223 +		VALIDATE_FD(shp, savefd);
       
   224 +
       
   225 +		sp = shp->sftable[origfd];
       
   226  		/* make saved file close-on-exec */
       
   227  		sh_fcntl(savefd,F_SETFD,FD_CLOEXEC);
       
   228  		if(origfd==job.fd)
       
   229 @@ -1655,6 +1692,7 @@ void	sh_iounsave(Shell_t* shp)
       
   230  			filemap[newfd++] = filemap[fd];
       
   231  		else
       
   232  		{
       
   233 +			VALIDATE_FD(shp, savefd);
       
   234  			shp->sftable[savefd] = 0;
       
   235  			sh_close(savefd);
       
   236  		}
       
   237 @@ -1678,16 +1716,19 @@ void	sh_iorestore(Shell_t *shp, int last
       
   238  		{
       
   239  			if ((savefd = filemap[fd].save_fd) >= 0)
       
   240  			{
       
   241 +				VALIDATE_FD(shp, savefd);
       
   242  				shp->sftable[savefd] = 0;
       
   243  				sh_close(savefd);
       
   244  			}
       
   245  			continue;
       
   246  		}
       
   247  		origfd = filemap[fd].orig_fd;
       
   248 +		VALIDATE_FD(shp, origfd);
       
   249  		if(origfd<0)
       
   250  		{
       
   251  			/* this should never happen */
       
   252  			savefd = filemap[fd].save_fd;
       
   253 +			VALIDATE_FD(shp, savefd);
       
   254  			shp->sftable[savefd] = 0;
       
   255  			sh_close(savefd);
       
   256  			return;
       
   257 @@ -1699,6 +1740,7 @@ void	sh_iorestore(Shell_t *shp, int last
       
   258  		sh_close(origfd);
       
   259  		if ((savefd = filemap[fd].save_fd) >= 0)
       
   260  		{
       
   261 +			VALIDATE_FD(shp, savefd);
       
   262  			sh_fcntl(savefd, F_DUPFD, origfd);
       
   263  			if(savefd==job.fd)
       
   264  				job.fd=origfd;
       
   265 @@ -1954,6 +1996,9 @@ static ssize_t slowread(Sfio_t *iop,void
       
   266  int sh_iocheckfd(Shell_t *shp, register int fd)
       
   267  {
       
   268  	register int flags, n;
       
   269 +
       
   270 +	VALIDATE_FD(shp, fd);
       
   271 +
       
   272  	if((n=shp->fdstatus[fd])&IOCLOSE)
       
   273  		return(n);
       
   274  	if(!(n&(IOREAD|IOWRITE)))
       
   275 @@ -2145,7 +2190,7 @@ static void	sftrack(Sfio_t* sp, int flag
       
   276  		return;
       
   277  	}
       
   278  #endif
       
   279 -	if(fd<0 || (fd>=shp->gd->lim.open_max && !sh_iovalidfd(shp,fd)))
       
   280 +	if (fd < 0 || !VALIDATE_FD(shp, fd))
       
   281  		return;
       
   282  	if(sh_isstate(SH_NOTRACK))
       
   283  		return;
       
   284 @@ -2413,6 +2458,8 @@ ssize_t sh_read(register int fd, void* b
       
   285  {
       
   286  	Shell_t *shp = sh_getinterp();
       
   287  	register Sfio_t *sp;
       
   288 +
       
   289 +	VALIDATE_FD(shp, fd);
       
   290  	if(sp=shp->sftable[fd])
       
   291  		return(sfread(sp,buff,n));
       
   292  	else
       
   293 @@ -2427,6 +2474,8 @@ ssize_t sh_write(register int fd, const 
       
   294  {
       
   295  	Shell_t *shp = sh_getinterp();
       
   296  	register Sfio_t *sp;
       
   297 +
       
   298 +	VALIDATE_FD(shp, fd);
       
   299  	if(sp=shp->sftable[fd])
       
   300  		return(sfwrite(sp,buff,n));
       
   301  	else
       
   302 @@ -2441,6 +2490,8 @@ off_t sh_seek(register int fd, off_t off
       
   303  {
       
   304  	Shell_t *shp = sh_getinterp();
       
   305  	register Sfio_t *sp;
       
   306 +
       
   307 +	VALIDATE_FD(shp, fd);
       
   308  	if((sp=shp->sftable[fd]) && (sfset(sp,0,0)&(SF_READ|SF_WRITE)))
       
   309  		return(sfseek(sp,offset,whence));
       
   310  	else
       
   311 @@ -2452,6 +2503,9 @@ int sh_dup(register int old)
       
   312  {
       
   313  	Shell_t *shp = sh_getinterp();
       
   314  	register int fd = dup(old);
       
   315 +
       
   316 +	VALIDATE_FD(shp, old);
       
   317 +	VALIDATE_FD(shp, fd);
       
   318  	if(fd>=0)
       
   319  	{
       
   320  		if(shp->fdstatus[old] == IOCLOSE)
       
   321 @@ -2473,13 +2527,15 @@ int sh_fcntl(register int fd, int op, ..
       
   322  	arg =  va_arg(ap, int) ;
       
   323  	va_end(ap);
       
   324  	newfd = fcntl(fd,op,arg);
       
   325 +
       
   326 +	VALIDATE_FD(shp, fd);
       
   327 +	VALIDATE_FD(shp, newfd);
       
   328 +
       
   329  	if(newfd>=0) switch(op)
       
   330  	{
       
   331  	    case F_DUPFD:
       
   332  		if(shp->fdstatus[fd] == IOCLOSE)
       
   333  			shp->fdstatus[fd] = 0;
       
   334 -		if(newfd>=shp->gd->lim.open_max)
       
   335 -			sh_iovalidfd(shp,newfd);
       
   336  		shp->fdstatus[newfd] = (shp->fdstatus[fd]&~IOCLEX);
       
   337  		if(fdnotify)
       
   338  			(*fdnotify)(fd,newfd);
       
   339 @@ -2548,6 +2604,7 @@ Sfio_t *sh_iogetiop(int fd, int mode)
       
   340  		return(iop);
       
   341  	if(mode==SF_READ && !(n&IOREAD))
       
   342  		return(iop);
       
   343 +	VALIDATE_FD(shp, fd);
       
   344  	if(!(iop = shp->sftable[fd]))
       
   345  		iop=sh_iostream(shp,fd);
       
   346  	return(iop);
       
   347 @@ -2567,7 +2624,10 @@ Sfio_t	*sh_fd2sfio(int fd)
       
   348  {
       
   349  	Shell_t	*shp = sh_getinterp();
       
   350  	register int status;
       
   351 -	Sfio_t *sp = shp->sftable[fd];
       
   352 +	Sfio_t *sp;
       
   353 +
       
   354 +	VALIDATE_FD(shp, fd);
       
   355 +	sp = shp->sftable[fd];
       
   356  	if(!sp  && (status = sh_iocheckfd(shp,fd))!=IOCLOSE)
       
   357  	{
       
   358  		register int flags=0;
       
   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.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
       
   362 @@ -25,6 +25,9 @@
       
   363   * AT&T Labs
       
   364   *
       
   365   */
       
   366 +/*
       
   367 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
       
   368 + */
       
   369  
       
   370  #include	<ast.h>
       
   371  #include	<stak.h>
       
   372 @@ -2053,6 +2056,7 @@ void	sh_syntax(Lex_t *lp)
       
   373  	else
       
   374  		lp->lastline = shp->inlineno;
       
   375  	tokstr = fmttoken(lp,tok,tokbuf);
       
   376 +	VALIDATE_FD(shp, shp->infd);
       
   377  	if((sp=fcfile()) || (shp->infd>=0 && (sp=shp->sftable[shp->infd])))
       
   378  	{
       
   379  		/* clear out any pending input */
       
   380 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/macro.c INIT.2011-02-08/src/cmd/ksh93/sh/macro.c
       
   381 --- INIT.2011-02-08.clean/src/cmd/ksh93/sh/macro.c	2012-05-02 03:16:26.100861446 -0700
       
   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 
       
   384  			sh_popcontext(mp->shp,&buff);
       
   385  			if(r==0 && ip && (ip->iofile&IOLSEEK))
       
   386  			{
       
   387 +				VALIDATE_FD(mp->shp, fd);
       
   388  				if(sp=mp->shp->sftable[fd])
       
   389  					num = sftell(sp);
       
   390  				else
       
   391 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/main.c INIT.2011-02-08/src/cmd/ksh93/sh/main.c
       
   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
       
   394 @@ -26,6 +26,9 @@
       
   395   * AT&T Labs
       
   396   *
       
   397   */
       
   398 +/*
       
   399 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
       
   400 + */
       
   401  
       
   402  #include	<ast.h>
       
   403  #include	<sfio.h>
       
   404 @@ -396,8 +399,10 @@ static void	exfile(register Shell_t *shp
       
   405  		if(fno > 0)
       
   406  		{
       
   407  			int r;
       
   408 +			VALIDATE_FD(shp, fno);
       
   409  			if(fno < 10 && ((r=sh_fcntl(fno,F_DUPFD,10))>=10))
       
   410  			{
       
   411 +				VALIDATE_FD(shp, r);
       
   412  				shp->fdstatus[r] = shp->fdstatus[fno];
       
   413  				sh_close(fno);
       
   414  				fno = r;
       
   415 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/path.c INIT.2011-02-08/src/cmd/ksh93/sh/path.c
       
   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
       
   418 @@ -23,6 +23,9 @@
       
   419   * AT&T Labs
       
   420   *
       
   421   */
       
   422 +/*
       
   423 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
       
   424 + */
       
   425  
       
   426  #include	"defs.h"
       
   427  #include	<fcin.h>
       
   428 @@ -1239,6 +1242,7 @@ static void exscript(Shell_t *shp,regist
       
   429  	if(sp=fcfile())
       
   430  		while(sfstack(sp,SF_POPSTACK));
       
   431  	job_clear();
       
   432 +	VALIDATE_FD(shp, shp->infd);
       
   433  	if(shp->infd>0 && (shp->fdstatus[shp->infd]&IOCLEX))
       
   434  		sh_close(shp->infd);
       
   435  	sh_setstate(sh_state(SH_FORKED));
       
   436 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/subshell.c INIT.2011-02-08/src/cmd/ksh93/sh/subshell.c
       
   437 --- INIT.2011-02-08.clean/src/cmd/ksh93/sh/subshell.c	2012-05-02 03:16:25.241021529 -0700
       
   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)
       
   440  		if((sp->tmpfd = fd = fcntl(1,F_DUPFD,10)) >= 0)
       
   441  		{
       
   442  			fcntl(fd,F_SETFD,FD_CLOEXEC);
       
   443 +			VALIDATE_FD(shp, fd);
       
   444  			shp->fdstatus[fd] = shp->fdstatus[1]|IOCLEX;
       
   445  			close(1);
       
   446  		}
       
   447 @@ -141,6 +142,7 @@ void	sh_subtmpfile(Shell_t *shp)
       
   448  		}
       
   449  		else
       
   450  		{
       
   451 +			VALIDATE_FD(shp, fd);
       
   452  			shp->fdstatus[fd] = IOREAD|IOWRITE;
       
   453  			sfsync(sfstdout);
       
   454  			if(fd==1)
       
   455 @@ -627,6 +629,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
       
   456  					((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT;
       
   457  					errormsg(SH_DICT,ERROR_system(1),e_toomany);
       
   458  				}
       
   459 +				VALIDATE_FD(shp, fd);
       
   460  				shp->sftable[fd] = iop;
       
   461  				fcntl(fd,F_SETFD,FD_CLOEXEC);
       
   462  				shp->fdstatus[fd] = (shp->fdstatus[1]|IOCLEX);
       
   463 diff -rupN INIT.2011-02-08.clean/src/cmd/ksh93/sh/xec.c INIT.2011-02-08/src/cmd/ksh93/sh/xec.c
       
   464 --- INIT.2011-02-08.clean/src/cmd/ksh93/sh/xec.c	2012-05-02 03:16:17.393286735 -0700
       
   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)
       
   467  	usepipe++;
       
   468  	fcntl(subpipe[0],F_SETFD,FD_CLOEXEC);
       
   469  	subpipe[2] = fcntl(1,F_DUPFD,10);
       
   470 +	VALIDATE_FD(shp, subpipe[1]);
       
   471 +	VALIDATE_FD(shp, subpipe[2]);
       
   472  	shp->fdstatus[subpipe[2]] = shp->fdstatus[1];
       
   473  	close(1);
       
   474  	fcntl(subpipe[1],F_DUPFD,1);
       
   475 @@ -117,6 +119,7 @@ static void iounpipe(Shell_t *shp)
       
   476  	usepipe = 0;
       
   477  	close(1);
       
   478  	fcntl(subpipe[2], F_DUPFD, 1);
       
   479 +	VALIDATE_FD(shp, subpipe[2]);
       
   480  	shp->fdstatus[1] = shp->fdstatus[subpipe[2]];
       
   481  	if(subdup) for(n=0; n < 10; n++)
       
   482  	{
       
   483 @@ -844,6 +847,7 @@ static int sh_coexec(Shell_t *shp,const 
       
   484  			if(filt > 2)
       
   485  			{
       
   486  				shp->coutpipe = shp->inpipe[1];
       
   487 +				VALIDATE_FD(shp, shp->coutpipe);
       
   488  				shp->fdptrs[shp->coutpipe] = &shp->coutpipe;
       
   489  			}
       
   490  		}
       
   491 @@ -1487,6 +1491,7 @@ int sh_exec(register const Shnode_t *t, 
       
   492  						if(shp->cpipe[0]<0 || shp->cpipe[1] < 0)
       
   493  						{
       
   494  							sh_copipe(shp,shp->outpipe=shp->cpipe,0);
       
   495 +							VALIDATE_FD(shp, shp->cpipe[0]);
       
   496  							shp->fdptrs[shp->cpipe[0]] = shp->cpipe;
       
   497  						}
       
   498  						sh_copipe(shp,shp->inpipe=pipes,0);
       
   499 @@ -3419,6 +3424,8 @@ static void coproc_init(Shell_t *shp, in
       
   500  		if((outfd=shp->cpipe[1]) < 10) 
       
   501  		{
       
   502  		        int fd=fcntl(shp->cpipe[1],F_DUPFD,10);
       
   503 +			VALIDATE_FD(shp, outfd);
       
   504 +			VALIDATE_FD(shp, fd);
       
   505  			if(fd>=10)
       
   506  			{
       
   507  			        shp->fdstatus[fd] = (shp->fdstatus[outfd]&~IOCLEX);
       
   508 @@ -3427,6 +3434,9 @@ static void coproc_init(Shell_t *shp, in
       
   509  				shp->cpipe[1] = fd;
       
   510  			}
       
   511  		}
       
   512 +		VALIDATE_FD(shp, shp->cpipe[0]);
       
   513 +		VALIDATE_FD(shp, shp->cpipe[1]);
       
   514 +
       
   515  		if(fcntl(*shp->cpipe,F_SETFD,FD_CLOEXEC)>=0)
       
   516  			shp->fdstatus[shp->cpipe[0]] |= IOCLEX;
       
   517  		shp->fdptrs[shp->cpipe[0]] = shp->cpipe;
       
   518 @@ -3437,7 +3447,9 @@ static void coproc_init(Shell_t *shp, in
       
   519  	shp->outpipe = shp->cpipe;
       
   520  	sh_pipe(shp->inpipe=pipes);
       
   521  	shp->coutpipe = shp->inpipe[1];
       
   522 +	VALIDATE_FD(shp, shp->coutpipe);
       
   523  	shp->fdptrs[shp->coutpipe] = &shp->coutpipe;
       
   524 +	VALIDATE_FD(shp, shp->outpipe[0]);
       
   525  	if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0)
       
   526  		shp->fdstatus[shp->outpipe[0]] |= IOCLEX;
       
   527  }
       
   528 @@ -3608,6 +3620,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons
       
   529  				int fd = shp->inpipe[1];
       
   530  				sh_iosave(shp,0,buff.topfd,(char*)0);
       
   531  				sh_iorenumber(shp,shp->inpipe[0],0);
       
   532 +				VALIDATE_FD(shp, fd);
       
   533  				if(fd>=0 && (!(otype&FPOU) || (otype&FCOOP)) && fcntl(fd,F_SETFD,FD_CLOEXEC)>=0)
       
   534  					shp->fdstatus[fd] |= IOCLEX;
       
   535  			}
       
   536 @@ -3619,6 +3632,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons
       
   537  #endif /* SHOPT_COSHELL */
       
   538  				sh_iosave(shp,1,buff.topfd,(char*)0);
       
   539  				sh_iorenumber(shp,sh_dup(shp->outpipe[1]),1);
       
   540 +				VALIDATE_FD(shp, shp->outpipe[0]);
       
   541  				if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0)
       
   542  					shp->fdstatus[shp->outpipe[0]] |= IOCLEX;
       
   543  			}
       
   544 @@ -3658,6 +3672,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons
       
   545  			signal(SIGQUIT,sh_fault);
       
   546  			signal(SIGINT,sh_fault);
       
   547  		}
       
   548 +		VALIDATE_FD(shp, shp->inpipe[1]);
       
   549  		if((otype&FPIN) && (!(otype&FPOU) || (otype&FCOOP)) && fcntl(shp->inpipe[1],F_SETFD,FD_CLOEXEC)>=0)
       
   550  			shp->fdstatus[shp->inpipe[1]] &= ~IOCLEX;
       
   551  		if(t->fork.forkio || otype)