1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Disallow >;word and <>;word for 'redirect' (re: 7b59fb80, 7b82c338)

The >;word and <>;word redirection operators cannot be used with
the 'exec' builtin, but the 'redirect' builtin (which used to be
an alias of 'command exec') permitted them. However, they do not
have the documented effect of the added ';'. So this commit blocks
those operators for 'redirect' as they are blocked for 'exec'.

It also tweaks redirect's error message if a non-redirection
argument is encountered.

src/cmd/ksh93/sh/parse.c: simple():
- Set the lexp->inexec flag for SYSREDIR (redirect) as well as
  SYSEXEC (exec). This flag is checked for in sh_lex() (lex.c) to
  throw a syntax error if one of these two operators is used.

src/cmd/ksh93/sh.1, src/cmd/ksh93/data/builtins.c:
- Documentation tweaks.

src/cmd/ksh93/sh/xec.c, src/cmd/ksh93/bltins/misc.c:
- When 'redirect' gives an 'incorrect syntax' (e_badsyntax) error
  message, include the first word that was found not to be a valid
  redirection. This is simply the first argument, as redirections
  are removed from the arguments list.

src/cmd/ksh93/tests/io.sh:
- Update test to reflect new error message format.
This commit is contained in:
Martijn Dekker 2021-02-06 22:00:55 +00:00
parent 43dfe3c8fa
commit 403e864ac8
6 changed files with 21 additions and 15 deletions

View file

@ -598,7 +598,7 @@ const char sh_optexec[] =
"[+?Because \bexec\b is a special built-in command, any failure will cause the "
"script or command line that invokes it to be aborted. This can be "
"prevented by invoking \bexec\b from the \bcommand\b utility.]"
"[+SEE ALSO?\bcommand\b(1), \beval\b(1), \bredirect(1)\b]"
"[+SEE ALSO?\bcommand\b(1), \beval\b(1), \bredirect\b(1)]"
;
const char sh_optexit[] =
@ -1447,7 +1447,7 @@ const char sh_optreadonly[] =
;
const char sh_optredirect[] =
"[-1c?\n@(#)$Id: redirect (ksh 93u+m) 2020-08-08 $\n]"
"[-1c?\n@(#)$Id: redirect (ksh 93u+m) 2021-02-06 $\n]"
"[--catalog?" SH_DICT "]"
"[+NAME?redirect - open/close and duplicate file descriptors]"
"[+DESCRIPTION?This command only accepts input/output redirections. "
@ -1455,9 +1455,10 @@ const char sh_optredirect[] =
"to \b9\b using the standard redirection mechanism available to all "
"commands, with the difference that the effect persists past the "
"execution of the \bredirect\b command.]"
"[+?Any file descriptor numbers greater than \b2\b that are opened with this "
"mechanism are closed when invoking another program, unless "
"explicitly redirected to themselves as part of that invocation.]"
"[+?When invoking another program, file descriptors greater than \b2\b that "
"were opened with this mechanism are only passed on if they are "
"explicitly redirected to themselves as part of the invocation "
"(e.g. \b4>&4\b) or if the \bposix\b option is set.]"
"[+?\bredirect\b cannot be invoked from a restricted shell to create "
"files or to open a file for writing or appending.]"
"\n"