ksh: Path-bound builtins cannot be executed by direct path
There are at least two bugs with the /opt/ast/bin
virtual directory path search and access mechanism for path-bound builtins.
One is that preceding command-local PATH assignments don’t work as specified:
$ builtin -d cat # make sure it's path-bound
$ (PATH=/opt/ast/bin:$PATH; cat --version)
version cat (AT&T Research) 2012-05-31
$ PATH=/opt/ast/bin:$PATH cat --version
cat: illegal option -- -
usage: cat [-benstuv] [file ...]
The second output is my external cat
, which is a bug. Both should show the AT&T version message.
The second bug is simpler:
$ /opt/ast/bin/cat
-ksh: /opt/ast/bin/cat: not found
This is ridiculous and probably violates POSIX. If a path can be found in $PATH
it should actually be invokable as that path. This also means you cannot trust the output of whence -p
and command -v
when /opt/ast/bin
is in the $PATH. For example, this common idiom breaks:
$ (PATH=/opt/ast/bin:$PATH; u=$(whence -p cat) && "$u" --version)
-ksh: /opt/ast/bin/cat: not found [No such file or directory]
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 28
Commits related to this issue
- Allow path-bound builtins on restricted shells If a system administrator prefixes /opt/ast/bin to the path and then invokes the shell in restricted mode, they clearly intend for the user to run those... — committed to ksh93/ksh by McDutchie 3 years ago
- Allow executing path-bound builtins by invoking their canonical path Path-bound builtins (such as /opt/ast/bin/cat) can now be executed by invoking the canonical path, so the following will now work:... — committed to ksh93/ksh by McDutchie 3 years ago
- Apply two fixes based on patches by @JohnoKing src/lib/libcmd/getconf.c: - Replace convoluted deferral to external command by a simple invocation of the path to the native getconf command determine... — committed to McDutchie/ksh by McDutchie 3 years ago
- patch documentation per https://github.com/ksh93/ksh/issues/138#issuecomment-817051318 — committed to McDutchie/ksh by McDutchie 3 years ago
- rm unused vars per https://github.com/ksh93/ksh/issues/138#issuecomment-817077001 — committed to McDutchie/ksh by McDutchie 3 years ago
- Allow invoking path-bound built-in commands by direct path or preceding `PATH` assignment (#275) Path-bound builtins on ksh (such as /opt/ast/bin/cat) break some basic assumptions about paths in the... — committed to ksh93/ksh by McDutchie 3 years ago
Sure. This behavior should at least be documented though:
I’ve encountered two bugs in the pathbound-builtins branch. The first bug is that running a builtin using
/opt/ast/bin
works in restricted shells, even though it shouldn’t:I’d say this behavior is a bug because it’s not behaving as documented in the man page, which states
rksh
forbids this practice:This patch should fix this issue:
For the second bug, the
getconf
,uname
and (possibly)date
libcmd builtins throw restricted errors when given an unrecognized option, rather than execute the equivalent external command:This is presumably occurs because
uname
anddate
run their external versions withcommand -px
(while the new patch forgetconf
also uses this method). I tried using a diff that just usescommand -x
, but that doesn’t work.When I comment out
nv_search
, the crash stops occurring:I’ve managed to reproduce the crash on Artix Linux using
CCFLAGS='-O0 -g -D_std_malloc'
. Backtrace from gdb: