1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

'.': disable ksh function lookup in POSIX mode

POSIXly, '.' loads only files, not functions.

This only applies to '.', not 'source' (which is not in POSIX).

src/cmd/ksh93/bltins/misc.c: b_source():
- For ksh function lookup, add an additional check that we're not
  in POSIX mode and running the '.' (SYSDOT) builtin.
This commit is contained in:
Martijn Dekker 2021-11-24 09:10:25 +01:00
parent c0334e32a1
commit 214308f81e
5 changed files with 28 additions and 2 deletions

6
NEWS
View file

@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh
Any uppercase BUG_* names are modernish shell bug IDs.
2021-11-24:
- The --posix mode was amended to stop the '.' command (but not 'source') from
looking up functions defined with the 'function' keyword. In the POSIX
standard and on other shells, the '.' command finds only script files.
2021-11-23:
- A bug was fixed that allowed arithmetic expressions to assign out-of-range

View file

@ -259,7 +259,7 @@ int b_dot_cmd(register int n,char *argv[],Shbltin_t *context)
{
/* check for KornShell style function first */
np = nv_search(script,shp->fun_tree,0);
if(np && is_afunction(np) && !nv_isattr(np,NV_FPOSIX))
if(np && is_afunction(np) && !nv_isattr(np,NV_FPOSIX) && !(sh_isoption(SH_POSIX) && shp->bltindata.bnode==SYSDOT))
{
if(!np->nvalue.ip)
{

View file

@ -21,7 +21,7 @@
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2021-11-23" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2021-11-24" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

View file

@ -7246,6 +7246,9 @@ enables the recognition of a leading zero as introducing an octal number in
all arithmetic evaluation contexts, except in the \fBlet\fR built-in while
\fBletoctal\fR is off;
.IP \[bu]
stops the \fB.\fR command (but not \fBsource\fR) from looking up functions
defined with the \fBfunction\fR syntax;
.IP \[bu]
changes the \fBtest\fR/\fB[\fR built-in command to make its deprecated
\fIexpr1\fR \fB-a\fR \fIexpr2\fR and \fIexpr1\fR \fB-o\fR \fIexpr2\fR operators
work even if \fIexpr1\fR equals "\fB!\fR" or "\fb(\fR" (which means the

View file

@ -903,5 +903,22 @@ got=$?
[[ $exp == $got ]] || err_exit "Test 7E: exit status or error message for exec'd command with long name wrong" \
"(expected $exp, got $got)"
# ======
if [[ -o ?posix ]]
then (
PATH=/dev/null
command set --posix
function dottest { :; }
. dottest
) 2>/dev/null && err_exit "'.' in POSIX mode finds ksh function"
(
PATH=/dev/null
command set --posix
function dottest { :; }
source dottest
) 2>/dev/null || err_exit "'source' in POSIX mode does not find ksh function"
fi
# ======
exit $((Errors<125?Errors:125))