1
0
Fork 0
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:
Martijn Dekker 2020-08-17 20:23:39 +01:00
parent acf84e9633
commit d03e948bcd
5 changed files with 44 additions and 7 deletions

View file

@ -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*)))
{