mirror of
				git://git.code.sf.net/p/cdesktopenv/code
				synced 2025-03-09 15:50:02 +00:00 
			
		
		
		
	Fix handling of skipped directories when autoloading functions
Fix a bug in autoloading functions. Directories in the path search
list which should be skipped (e.g. because they don't exist) did
not interact correctly with autoloaded functions, so that a
function to autoload was not always found.
Details:
https://github.com/att/ast/issues/1454
Fix backported (and cleaned up) from:
3bc58164
src/cmd/ksh93/sh/path.c:
- path_opentype(): Fix the path search loop so that entries marked
  with PATH_SKIP are handled correctly.
src/cmd/ksh93/tests/functions.sh:
- Add regression test verifying an autoloaded function with a PATH
  that triggered the bug.
  The bug in path_opentype() fixed by this commit may affect other
  scenarios but we know it affects autoloaded functions. Hence the
  test for that scenario.
(cherry picked from commit a27903165775309f4f032de5d42ec1785f14cfbc)
			
			
This commit is contained in:
		
							parent
							
								
									482d1c3dd6
								
							
						
					
					
						commit
						eee47df423
					
				
					 4 changed files with 49 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -508,7 +508,8 @@ static int	path_opentype(Shell_t *shp,const char *name, register Pathcomp_t *pp,
 | 
			
		|||
{
 | 
			
		||||
	register int fd= -1;
 | 
			
		||||
	struct stat statb;
 | 
			
		||||
	Pathcomp_t *oldpp;
 | 
			
		||||
	Pathcomp_t *nextpp;
 | 
			
		||||
 | 
			
		||||
	if(!pp && !shp->pathlist)
 | 
			
		||||
		path_init(shp);
 | 
			
		||||
	if(!fun && strchr(name,'/'))
 | 
			
		||||
| 
						 | 
				
			
			@ -516,12 +517,15 @@ static int	path_opentype(Shell_t *shp,const char *name, register Pathcomp_t *pp,
 | 
			
		|||
		if(sh_isoption(SH_RESTRICTED))
 | 
			
		||||
			errormsg(SH_DICT,ERROR_exit(1),e_restricted,name);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	nextpp = pp;
 | 
			
		||||
	do
 | 
			
		||||
	{
 | 
			
		||||
		pp = path_nextcomp(shp,oldpp=pp,name,0);
 | 
			
		||||
		while(oldpp && (oldpp->flags&PATH_SKIP))
 | 
			
		||||
			oldpp = oldpp->next;
 | 
			
		||||
		if(fun && (!oldpp || !(oldpp->flags&PATH_FPATH)))
 | 
			
		||||
		pp = nextpp;
 | 
			
		||||
		nextpp = path_nextcomp(shp,pp,name,0);
 | 
			
		||||
		if(pp && (pp->flags&PATH_SKIP))
 | 
			
		||||
			continue;
 | 
			
		||||
		if(fun && (!pp || !(pp->flags&PATH_FPATH)))
 | 
			
		||||
			continue;
 | 
			
		||||
		if((fd = sh_open(path_relative(shp,stakptr(PATH_OFFSET)),O_RDONLY,0)) >= 0)
 | 
			
		||||
		{
 | 
			
		||||
| 
						 | 
				
			
			@ -533,7 +537,8 @@ static int	path_opentype(Shell_t *shp,const char *name, register Pathcomp_t *pp,
 | 
			
		|||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	while( fd<0 && pp);
 | 
			
		||||
	while(fd<0 && nextpp);
 | 
			
		||||
 | 
			
		||||
	if(fd>=0 && (fd = sh_iomovefd(fd)) > 0)
 | 
			
		||||
	{
 | 
			
		||||
		fcntl(fd,F_SETFD,FD_CLOEXEC);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue