From 61d9bca5817a698a81c80cb9f2bdea95b213c8e8 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 7 Jun 2020 02:36:54 +0200 Subject: [PATCH] POSIX compliance: rm harmful default aliases 'command '/'nohup ' Continuing alias substitution after 'command' (due to the final space in the alias) is inherently broken and doing so by default is incompatible with the POSIX standard, as aliases may contain arbitrary shell grammar. For instance, until the previous commit, the POSIX standard 'times' command was an alias: times='{ { time;} 2>&1;}' -- and so, of course, 'command times' gave a syntax error, although this is a perfectly valid POSIX idiom that must be supported. 'command' is specified by POSIX as a regular builtin, not an alias. Therefore it should always bypass aliases just as it bypasses functions to expose standard builtin and external commands. I can only imagine that the reason for this command='command ' alias was that some standard commands themselves were implemented as aliases, and POSIX requires that standard commands are accessible with the 'command' prefix. But implementing standard commands as aliases is itself inherently broken. It never worked for 'command times', as shown; and in any case, removing all aliases with 'unalias -a' should not get rid of standard commands. Similarly, the default alias nohup='nohup ' is also harmful. Anyone who really wants to keep this behaviour can just define these aliases themselves in their script or ~/.kshrc file. src/cmd/ksh93/data/aliases.c: - Remove default alias command='command '. - Remove default alias nohup='nohup '. src/cmd/ksh93/sh.1 - Remove the above default aliases from the list. - Mention that the 'command' builtin does not search for aliases. (cherry picked from commit 5cfe7c4e2015b7445da24983af5008035c4b6e1e) --- NEWS | 6 ++++++ TODO | 20 -------------------- src/cmd/ksh93/data/aliases.c | 2 -- src/cmd/ksh93/sh.1 | 6 +----- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/NEWS b/NEWS index 53d727d43..ab951b925 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,12 @@ Any uppercase BUG_* names are modernish shell bug IDs. another with those used by all of the shell's child processes. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_27 +- The default aliases command='command ' and nohup='nohup ' have been + removed because they caused breakage in an attempt to circumvent other + breakage which is being fixed. In the unlikely even that anyone still + needs alias substitution to continue on the command argument following + 'command' or 'nohup', it's easy to set these aliases yourself. + 2020-06-05: - Fix a bug that caused special variables such as PATH, LANG, LC_ALL, diff --git a/TODO b/TODO index 773850908..b24f59335 100644 --- a/TODO +++ b/TODO @@ -10,29 +10,9 @@ Fix build failures: - ksh does not currently build on AIX, HP-UX, Solaris, or QNX. -______ -Remove hack for 'test -t' with no args == 'test -t 1': -- from sh/parse.c, qscan() -- from bltins/test.c - ______ Fix or remove broken default aliases: -- Remove alias times='{ { time;} 2>&1;}' which does not produce POSIX- - compliant output; reimplement as a proper POSIX-compliant builtin. - In any case, implementing a standard utility as an alias is unacceptable - as 'unalias -a' (remove all aliases) should not remove standard utilities! - Backport the builtin from the abandoned Vashisht/Rader branch: - https://github.com/att/ast/pull/1332 - -- Remove alias command='command '. Continuing alias substitution after - 'command' (due to the final space in the alias) is inherently broken, as - aliases may contain arbitrary shell grammar. For instance, when combining - this default alias with the default 'times' alias ('command times'), which - is perfectly valid per POSIX, you get a syntax error! - -- Remove alias nohup='nohup '. Same reason as for 'command ' above. - - Remove pointless default aliases 'fc' and 'type'; these are already implemented as normal shell builtins. Add man page entries for these. diff --git a/src/cmd/ksh93/data/aliases.c b/src/cmd/ksh93/data/aliases.c index fab6476dc..61e0b2dec 100644 --- a/src/cmd/ksh93/data/aliases.c +++ b/src/cmd/ksh93/data/aliases.c @@ -33,7 +33,6 @@ const struct shtable2 shtab_aliases[] = "2d", NV_NOFREE, "set -f;_2d", #endif /* SHOPT_FS_3D */ "autoload", NV_NOFREE, "typeset -fu", - "command", NV_NOFREE, "command ", "compound", NV_NOFREE|BLT_DCL, "typeset -C", "fc", NV_NOFREE, "hist", "float", NV_NOFREE|BLT_DCL, "typeset -lE", @@ -42,7 +41,6 @@ const struct shtable2 shtab_aliases[] = "history", NV_NOFREE, "hist -l", "integer", NV_NOFREE|BLT_DCL, "typeset -li", "nameref", NV_NOFREE|BLT_DCL, "typeset -n", - "nohup", NV_NOFREE, "nohup ", "r", NV_NOFREE, "hist -s", "redirect", NV_NOFREE, "command exec", "source", NV_NOFREE, "command .", diff --git a/src/cmd/ksh93/sh.1 b/src/cmd/ksh93/sh.1 index acb78fac3..4a7bf1e1a 100644 --- a/src/cmd/ksh93/sh.1 +++ b/src/cmd/ksh93/sh.1 @@ -790,8 +790,6 @@ but can be unset or redefined: .TP .B "autoload=\(fmtypeset \-fu\(fm" .TP -.B "command=\(fmcommand \(fm" -.TP .B "compound=\(fmtypeset \-C\(fm" .TP .B "fc=hist" @@ -808,8 +806,6 @@ but can be unset or redefined: .TP .B "nameref=\(fmtypeset \-n\(fm" .TP -.B "nohup=\(fmnohup \(fm" -.TP .B "r=\(fmhist \-s\(fm" .TP .B "redirect=\(fmcommand exec\(fm" @@ -5811,7 +5807,7 @@ the operating system's standard utilities path rather than the one defined by the value of .SM .BR PATH . -Functions will not be searched for when finding +Functions and aliases will not be searched for when finding .IR name . In addition, if .I name\^