-
Notifications
You must be signed in to change notification settings - Fork 153
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
bug involving the handling of paths marked PATH_SKIP #1454
Comments
I forgot to mention another curious thing. In the reproduction script if you insert |
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: att#1454 Fix backported (and cleaned up) from: att@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)
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: att#1454 Fix backported (and cleaned up) from: att@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)
While working on #1445 I was surprised to find that the fix worked on almost all platforms, both my local ones and on Travis CI. One platform where it failed was Ubuntu. After many hours adding strategic
DPRINTF()
calls I found the bug is inpath_opentype()
. Specifically, how it handles path entries taggedPATH_SKIP
because they do not exist (or can't be stat()'d for some reason) or are duplicates of other$PATH
entries. This happens on Ubuntu when using the$PATH
in the script below because /bin is a symlink to /usr/bin which means /bin is flagged to be skipped. That it is the final entry in$PATH
is important.This bug exists in the ksh93u+ release as well as git master. You can trigger the bug by saving the following to /tmp/path_skip:
Running
ksh /tmp/path_skip xyz
will fail with this output:The content of the /tmp/usr/bin/cd file created by the above script is from Fedora 28 but an equivalent script is found on most platforms. Notice that what ksh has done is
source
'd that script. Thebuiltin: xyz: not found
error is becausea)
builtin
in ksh has different behavior than in bash, andb) ksh did not set
$@
to the args (i.e.,/usr
) that were passed to the command. Instead it passed the shell's top-level argv.We may not be able to change (a) above since doing so without breaking backward compatibility is probably not possible. But (b) looks like a bug to me. On the other hand it's possible this seemingly incorrect behavior will never occur if the core bug this issue documents is fixed.
P.S., As I was writing this it occurred to me to test all the ksh93u+ binaries I have ready access to. All of them, with the exception of OpenSuse 42, failed. It turns out OpenSuse has a "fix" for this bug:
The scare-quotes are intentional because it only papers over the bug and doesn't address the more fundamental problems with the structure of
path_opentype()
.The text was updated successfully, but these errors were encountered: