check not-begun heredocs at EOF earlier

izabera reported they were not caught with “set -n”
This commit is contained in:
tg 2016-03-01 18:30:05 +00:00
parent 25a564460e
commit c2bdb1b9dd
4 changed files with 47 additions and 22 deletions

36
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.725 2016/02/26 22:03:10 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.726 2016/03/01 18:30:01 tg Exp $
# -*- mode: sh -*-
#-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -30,7 +30,7 @@
# (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
expected-stdout:
@(#)MIRBSD KSH R52 2016/02/26
@(#)MIRBSD KSH R52 2016/03/01
description:
Check version of shell.
stdin:
@ -39,7 +39,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R52 2016/02/26
@(#)LEGACY KSH R52 2016/03/01
description:
Check version of legacy shell.
stdin:
@ -2249,7 +2249,7 @@ expected-stdout:
hi
there
---
name: heredoc-4
name: heredoc-4a
description:
Check that an error occurs if the heredoc-delimiter is missing.
stdin: !
@ -2259,6 +2259,34 @@ stdin: !
expected-exit: e > 0
expected-stderr-pattern: /.*/
---
name: heredoc-4an
description:
Check that an error occurs if the heredoc-delimiter is missing.
arguments: !-n!
stdin: !
cat << EOF
hi
there
expected-exit: e > 0
expected-stderr-pattern: /.*/
---
name: heredoc-4b
description:
Check that an error occurs if the heredoc is missing.
stdin: !
cat << EOF
expected-exit: e > 0
expected-stderr-pattern: /.*/
---
name: heredoc-4bn
description:
Check that an error occurs if the heredoc is missing.
arguments: !-n!
stdin: !
cat << EOF
expected-exit: e > 0
expected-stderr-pattern: /.*/
---
name: heredoc-5
description:
Check that backslash quotes a $, ` and \ and kills a \newline

9
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.171 2016/01/21 18:24:39 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.172 2016/03/01 18:30:04 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
@ -1581,13 +1581,6 @@ herein(struct ioword *iop, char **resbuf)
struct temp *h;
int i;
/* ksh -c 'cat <<EOF' can cause this... */
if (iop->heredoc == NULL && !(iop->ioflag & IOHERESTR)) {
warningf(true, Tmissinghere);
/* special to iosetup(): don't print error */
return (-2);
}
/* lexer substitution flags */
i = (iop->ioflag & IOEVAL) ? (ONEWORD | HEREDOC) : 0;

14
lex.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.220 2016/03/01 18:00:08 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.221 2016/03/01 18:30:04 tg Exp $");
/*
* states while lexing word
@ -1000,6 +1000,16 @@ yylex(int cf)
if (cf & CONTIN)
goto Again;
}
} else if (c == '\0' && !(cf & HEREDELIM)) {
struct ioword **p = heres;
while (p < herep)
if ((*p)->ioflag & IOHERESTR)
++p;
else
/* ksh -c 'cat <<EOF' can cause this */
yyerror("here document '%s' unclosed\n",
evalstr((*p)->delim, 0));
}
return (c);
}
@ -1173,7 +1183,7 @@ readhere(struct ioword *iop)
while (c != '\n') {
if (!c)
/* oops, reached EOF */
yyerror("%s '%s' unclosed\n", Theredoc, eof);
yyerror("here document '%s' unclosed\n", eof);
/* store character */
Xcheck(xs, xp);
Xput(xs, xp, c);

10
sh.h
View File

@ -175,9 +175,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.765 2016/02/26 21:53:37 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.766 2016/03/01 18:30:05 tg Exp $");
#endif
#define MKSH_VERSION "R52 2016/02/26"
#define MKSH_VERSION "R52 2016/03/01"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -887,12 +887,6 @@ EXTERN const char T_funny_command[] E_INIT("funny $() command");
EXTERN const char Tfg_badsubst[] E_INIT("fileglob: bad substitution");
#endif
#define Tbadsubst (Tfg_badsubst + 10) /* "bad substitution" */
#if defined(__GNUC__)
#define Tmissinghere "missing here document"
#else
EXTERN const char Tmissinghere[] E_INIT("missing here document");
#endif
#define Theredoc (Tmissinghere + 8) /* "here document" */
EXTERN const char TC_LEX1[] E_INIT("|&;<>() \t\n");
#define TC_IFSWS (TC_LEX1 + 7) /* space tab newline */