mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix 'command -p' lookup if hash table entry exists (re: c9ccee86
)
If a command's path was previously added to the hash table as a 'tracked alias', then the hash table entry was used, bypassing the default utility path search activated by 'command -p'. 'command -p' activates a SH_DEFPATH shell state. The bug was caused by a failure to check for this state before using the hash table. This check needs to be added in four places. src/cmd/ksh93/sh/path.c, src/cmd/ksh93/sh/xec.c: - path_search(), path_spawn(), sh_exec(), sh_ntfork(): Only consult the hash table, which is shp->track_tree, if the SH_DEFPATH shell state is not active. src/cmd/ksh93/tests/path.sh: - Add regress tests checking that 'command -p' and 'command -p -v' still search in the default path if a hash table entry exists for the command searched.
This commit is contained in:
parent
acf84e9633
commit
d03e948bcd
5 changed files with 44 additions and 7 deletions
|
@ -696,7 +696,12 @@ int path_search(Shell_t *shp,register const char *name,Pathcomp_t **oldpp, int f
|
|||
path_init(shp);
|
||||
if(flag)
|
||||
{
|
||||
if(!(flag&1) && (np=nv_search(name,shp->track_tree,0)) && !nv_isattr(np,NV_NOALIAS) && (pp=(Pathcomp_t*)np->nvalue.cp))
|
||||
/* if a tracked alias exists and we're not searching the default path, use it */
|
||||
if(!sh_isstate(SH_DEFPATH)
|
||||
&& !(flag&1)
|
||||
&& (np=nv_search(name,shp->track_tree,0))
|
||||
&& !nv_isattr(np,NV_NOALIAS)
|
||||
&& (pp=(Pathcomp_t*)np->nvalue.cp))
|
||||
{
|
||||
stakseek(PATH_OFFSET);
|
||||
path_nextcomp(shp,pp,name,pp);
|
||||
|
@ -1070,7 +1075,8 @@ pid_t path_spawn(Shell_t *shp,const char *opath,register char **argv, char **env
|
|||
pidsize = sfprintf(stkstd,"*%d*",spawn?getpid():getppid());
|
||||
stakputs(opath);
|
||||
opath = stakfreeze(1)+PATH_OFFSET+pidsize;
|
||||
np=nv_search(argv[0],shp->track_tree,0);
|
||||
/* only use tracked alias if we're not searching default path */
|
||||
np = sh_isstate(SH_DEFPATH) ? NIL(Namval_t*) : nv_search(argv[0],shp->track_tree,0);
|
||||
while(libpath && !libpath->lib)
|
||||
libpath=libpath->next;
|
||||
if(libpath && (!np || nv_size(np)>0))
|
||||
|
|
|
@ -1221,7 +1221,11 @@ int sh_exec(register const Shnode_t *t, int flags)
|
|||
}
|
||||
else
|
||||
{
|
||||
if((np=nv_search(com0,shp->track_tree,0)) && !nv_isattr(np,NV_NOALIAS) && np->nvalue.cp)
|
||||
/* if a tracked alias exists and we're not searching the default path, use it */
|
||||
if(!sh_isstate(SH_DEFPATH)
|
||||
&& (np=nv_search(com0,shp->track_tree,0))
|
||||
&& !nv_isattr(np,NV_NOALIAS)
|
||||
&& np->nvalue.cp)
|
||||
np=nv_search(nv_getval(np),shp->bltin_tree,0);
|
||||
else
|
||||
np = 0;
|
||||
|
@ -3639,7 +3643,11 @@ static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,in
|
|||
if(!strchr(path=argv[0],'/'))
|
||||
{
|
||||
Namval_t *np;
|
||||
if((np=nv_search(path,shp->track_tree,0)) && !nv_isattr(np,NV_NOALIAS) && np->nvalue.cp)
|
||||
/* if a tracked alias exists and we're not searching the default path, use it */
|
||||
if(!sh_isstate(SH_DEFPATH)
|
||||
&& (np=nv_search(path,shp->track_tree,0))
|
||||
&& !nv_isattr(np,NV_NOALIAS)
|
||||
&& np->nvalue.cp)
|
||||
path = nv_getval(np);
|
||||
else if(path_absolute(shp,path,NIL(Pathcomp_t*)))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue