disable parsing of &> as GNU bash iop if -o posix or -o sh, based on IRC discussion where jilles(IIRC) pointed out it breaks existing valid scripts

This commit is contained in:
tg 2013-03-24 15:01:50 +00:00
parent 8697048c2c
commit a3b5e77c6c
4 changed files with 31 additions and 8 deletions

21
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.600 2013/03/24 00:56:19 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.601 2013/03/24 15:01:46 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -29,7 +29,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout:
@(#)MIRBSD KSH R44 2013/03/23
@(#)MIRBSD KSH R44 2013/03/24
description:
Check version of shell.
stdin:
@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R44 2013/03/23
@(#)LEGACY KSH R44 2013/03/24
description:
Check version of legacy shell.
stdin:
@ -8511,6 +8511,21 @@ expected-stdout:
ras
dwa
---
name: bashiop-5
description:
Check if GNU bash-like I/O redirection is only supported
in !POSIX !sh mode as it breaks existing scripts' syntax
(tested only on MirBSD as it uses /dev/fd)
category: os:mirbsd
stdin:
"$__progname" -c 'echo foo>/dev/null&>/dev/fd/2 echo bar1'
"$__progname" -o posix -c 'echo foo>/dev/null&>/dev/fd/2 echo bar2'
"$__progname" -o sh -c 'echo foo>/dev/null&>/dev/fd/2 echo bar3'
expected-stderr:
foo echo bar1
bar2
bar3
---
name: mkshiop-1
description:
Check for support of more than 9 file descriptors

5
lex.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.182 2013/02/19 18:45:20 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.183 2013/03/24 15:01:48 tg Exp $");
/*
* states while lexing word
@ -898,7 +898,8 @@ yylex(int cf)
state = SBASE;
dp = Xstring(ws, wp);
if ((c == '<' || c == '>' || c == '&') && state == SBASE) {
if (state == SBASE && (c == '<' || c == '>' ||
(!Flag(FSH) && !Flag(FPOSIX) && c == '&'))) {
struct ioword *iop = alloc(sizeof(struct ioword), ATEMP);
if (Xlength(ws, wp) == 0)

9
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.306 2013/03/24 00:56:23 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.307 2013/03/24 15:01:49 tg Exp $
.\" $OpenBSD: ksh.1,v 1.145 2013/01/17 21:20:25 jmc Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -2434,6 +2434,13 @@ in
.Nm
but a syntax error in GNU
.Nm bash .
Setting the
.Fl o Ar posix
or
.Fl o Ar sh
shell options disable parsing of this redirection;
it's a compatibility feature to legacy scripts, to
not be used when writing new shell code.
.It Xo
.No &\*(Gt\*(Ba Ar file ,
.No &\*(Gt\*(Gt Ar file ,

4
sh.h
View File

@ -164,9 +164,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.643 2013/03/24 00:56:25 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.644 2013/03/24 15:01:50 tg Exp $");
#endif
#define MKSH_VERSION "R44 2013/03/23"
#define MKSH_VERSION "R44 2013/03/24"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES