After discussions with Jilles Tjoelker (FreeBSD shell) and
following a suggestion from him, the way the fix to PR bin/50993 was implemented has changed a little. There are three steps involved in processing a here document, reading it, parsing it, and then evaluating it before applying it to the correct file descriptor for the command to use. The third of those is not related to this problem, and has not changed. The bug was caused by combining the first two steps into one (and not doing it correctly - which would be hard that way.) The fix is to split the first two stages into separate events. The original fix moved the 2nd stage (parsing) to just immediately before the 3rd stage (evaluation.) Jilles pointed out some unwanted side effects from doing it that way, and suggested moving the 2nd stage to immediately after the first. This commit makes that change. The effect is to revert the changes to expand.c and parser.h (which are no longer needed) and simplify slightly the change to parser.c. (from kre@)
This commit is contained in:
parent
e7b323ca74
commit
65cf828420
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: parser.c,v 1.114 2016/03/31 16:12:52 christos Exp $ */
|
||||
/* $NetBSD: parser.c,v 1.115 2016/03/31 23:11:05 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: parser.c,v 1.114 2016/03/31 16:12:52 christos Exp $");
|
||||
__RCSID("$NetBSD: parser.c,v 1.115 2016/03/31 23:11:05 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -109,7 +109,7 @@ STATIC union node *command(void);
|
|||
STATIC union node *simplecmd(union node **, union node *);
|
||||
STATIC union node *makename(void);
|
||||
STATIC void parsefname(void);
|
||||
STATIC void slurp_heredoc(char *const, int, int);
|
||||
STATIC void slurp_heredoc(char *const, const int, const int);
|
||||
STATIC void readheredocs(void);
|
||||
STATIC int peektoken(void);
|
||||
STATIC int readtoken(void);
|
||||
|
@ -759,7 +759,7 @@ checkend(int c, char * const eofmark, const int striptabs)
|
|||
*/
|
||||
|
||||
STATIC void
|
||||
slurp_heredoc(char *const eofmark, int striptabs, int sq)
|
||||
slurp_heredoc(char *const eofmark, const int striptabs, const int sq)
|
||||
{
|
||||
int c;
|
||||
char *out;
|
||||
|
@ -852,28 +852,21 @@ readheredocs(void)
|
|||
n->narg.text = wordtext;
|
||||
n->narg.backquote = backquotelist;
|
||||
here->here->nhere.doc = n;
|
||||
|
||||
if (here->here->nhere.type == NHERE)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Now "parse" here docs that have unquoted eofmarkers.
|
||||
*/
|
||||
setinputstring(wordtext, 1);
|
||||
readtoken1(pgetc(), DQSYNTAX, 1);
|
||||
n->narg.text = wordtext;
|
||||
n->narg.backquote = backquotelist;
|
||||
popfile();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
parse_heredoc(union node *n)
|
||||
{
|
||||
if (n->narg.type != NARG)
|
||||
abort();
|
||||
|
||||
if (n->narg.text[0] == '\0') /* nothing to do */
|
||||
return;
|
||||
|
||||
setinputstring(n->narg.text, 1);
|
||||
|
||||
readtoken1(pgetc(), DQSYNTAX, 1);
|
||||
|
||||
n->narg.text = wordtext;
|
||||
n->narg.backquote = backquotelist;
|
||||
|
||||
popfile();
|
||||
}
|
||||
|
||||
STATIC int
|
||||
peektoken(void)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: parser.h,v 1.20 2016/03/27 14:39:33 christos Exp $ */
|
||||
/* $NetBSD: parser.h,v 1.21 2016/03/31 23:11:05 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
|
@ -81,6 +81,5 @@ extern int whichprompt; /* 1 == PS1, 2 == PS2 */
|
|||
|
||||
union node *parsecmd(int);
|
||||
void fixredir(union node *, const char *, int);
|
||||
void parse_heredoc(union node *);
|
||||
int goodname(char *);
|
||||
const char *getprompt(void *);
|
||||
|
|
Loading…
Reference in New Issue