Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a two decade old bug in whence -a #25

Merged
merged 1 commit into from
Jun 19, 2020

Conversation

JohnoKing
Copy link

@JohnoKing JohnoKing commented Jun 18, 2020

This pull request (which is properly tested this time) fixes a bug that was originally reported by @DavidMorano about two decades ago to the AST team (ref att#954). whence -a bases the path for tracked aliases on the user's current working directory if it an enabled ksh builtin of the same name is also available. The following example will claim cat is in the user's current working directory:

$ whence -a cat
cat is a tracked alias for /usr/bin/cat
$ builtin cat
$ whence -a cat
cat is a shell builtin
cat is /usr/bin/cat
cat is a tracked alias for /home/youruser/cat

This happens because whence -a determines the path to tracked aliases with path_pwd, which is only meant for getting the current working directory (like pwd). The fix is to properly save the path of the tracked alias for use with whence -a.

Note: If the first whence -a command in the example is not run first, whence will claim cat is an undefined function. This is unfortunately not fixed by this pull request.

This bug was originally reported by @DavidMorano about two
decades ago to the AST team (ref att#954). `whence -a`
bases the path for tracked aliases on the user's current working
directory if it an enabled ksh builtin of the same name is
also available. The following example will claim `cat` is in
the user's current working directory:

$ whence -a
cat is a tracked alias for /usr/bin/cat
$ builtin cat
$ whence -a cat
cat is a shell builtin
cat is /usr/bin/cat
cat is a tracked alias for /current/working/directory/cat

This patch from ksh2020 (att#1049) fixes this problem by
properly saving the path of the tracked alias for use with
`whence -a`, since `path_pwd` (as implied by the function's
name) only gets the users current working directory, not the
location of tracked aliases.

src/cmd/ksh93/bltins/whence.c:
 - Print the actual path of a tracked alias, path_pwd doesn't
   have this functionality.

src/cmd/ksh93/include/name.h:
 - Add `pathcomp` for saving the value of tracked aliases.

src/cmd/ksh93/sh/path.c:
 - Save the value of tracked aliases for use by whence.

src/cmd/ksh93/tests/builtins.sh:
 - Add a regression test for using `whence -a` on tracked
   aliases with a builtin equivalent.
@McDutchie
Copy link

McDutchie commented Jun 19, 2020

Hmm. For the first whence -a command in your example, which I think is meant to be whence -a cat (copy/paste error?), it looks like a simple whence cat will also suffice to make it stop claiming it's an "undefined function". Anyway, that's another bug that needs a separate issue opening. Edit: Done: #26

Thanks for the pull request – looks good.

@JohnoKing
Copy link
Author

For the first whence -a command in your example, which I think is meant to be whence -a cat (copy/paste error?)

That was a copy/paste error, thanks for pointing that out.

@McDutchie McDutchie merged commit 4956aa4 into ksh93:master Jun 19, 2020
McDutchie pushed a commit that referenced this pull request Jun 19, 2020
'whence -a' bases the path for tracked aliases on the user's
current working directory if an enabled ksh builtin of the same
name is also available. The following example will claim 'cat'
is in the user's current working directory:

$ whence -a cat
cat is a tracked alias for /usr/bin/cat
$ builtin cat
$ whence -a cat
cat is a shell builtin
cat is /usr/bin/cat
cat is a tracked alias for /current/working/directory/cat

This patch from ksh2020 fixes this problem by properly saving the
path of the tracked alias for use with 'whence -a', since
'path_pwd' (as implied by the function's name) only gets the users
current working directory, not the location of tracked aliases.
Ref.: att#1049

This bug was originally reported by David Morano about two decades
ago to the AST team: att#954

src/cmd/ksh93/bltins/whence.c:
 - Print the actual path of a tracked alias, path_pwd doesn't
   have this functionality.

src/cmd/ksh93/include/name.h:
 - Add 'pathcomp' for saving the value of tracked aliases.

src/cmd/ksh93/sh/path.c:
 - Save the value of tracked aliases for use by whence.

src/cmd/ksh93/tests/builtins.sh:
 - Add a regression test for using 'whence -a' on tracked
   aliases with a builtin equivalent.
@JohnoKing JohnoKing deleted the fix-whence-a branch June 20, 2020 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants