Mon Nov 12 08:46:54 2018 UTC ()
Pull up following revision(s) (requested by kre in ticket #1086):

	bin/sh/parser.c: revision 1.152

PR bin/53712

Avoid crash from redirect on null compound command.


(martin)
diff -r1.132.2.6 -r1.132.2.7 src/bin/sh/parser.c

cvs diff -r1.132.2.6 -r1.132.2.7 src/bin/sh/parser.c (expand / switch to unified diff)

--- src/bin/sh/parser.c 2018/09/10 15:45:11 1.132.2.6
+++ src/bin/sh/parser.c 2018/11/12 08:46:54 1.132.2.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: parser.c,v 1.132.2.6 2018/09/10 15:45:11 martin Exp $ */ 1/* $NetBSD: parser.c,v 1.132.2.7 2018/11/12 08:46:54 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1991, 1993 4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Kenneth Almquist. 8 * Kenneth Almquist.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36#ifndef lint 36#ifndef lint
37#if 0 37#if 0
38static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; 38static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
39#else 39#else
40__RCSID("$NetBSD: parser.c,v 1.132.2.6 2018/09/10 15:45:11 martin Exp $"); 40__RCSID("$NetBSD: parser.c,v 1.132.2.7 2018/11/12 08:46:54 martin Exp $");
41#endif 41#endif
42#endif /* not lint */ 42#endif /* not lint */
43 43
44#include <stdio.h> 44#include <stdio.h>
45#include <stdlib.h> 45#include <stdlib.h>
46#include <limits.h> 46#include <limits.h>
47 47
48#include "shell.h" 48#include "shell.h"
49#include "parser.h" 49#include "parser.h"
50#include "nodes.h" 50#include "nodes.h"
51#include "expand.h" /* defines rmescapes() */ 51#include "expand.h" /* defines rmescapes() */
52#include "eval.h" /* defines commandname */ 52#include "eval.h" /* defines commandname */
53#include "syntax.h" 53#include "syntax.h"
@@ -587,27 +587,27 @@ command(void) @@ -587,27 +587,27 @@ command(void)
587 synexpect(-1, 0); 587 synexpect(-1, 0);
588 /* NOTREACHED */ 588 /* NOTREACHED */
589 } 589 }
590 590
591 /* Now check for redirection which may follow command */ 591 /* Now check for redirection which may follow command */
592 while (readtoken() == TREDIR) { 592 while (readtoken() == TREDIR) {
593 *rpp = n2 = redirnode; 593 *rpp = n2 = redirnode;
594 rpp = &n2->nfile.next; 594 rpp = &n2->nfile.next;
595 parsefname(); 595 parsefname();
596 } 596 }
597 tokpushback++; 597 tokpushback++;
598 *rpp = NULL; 598 *rpp = NULL;
599 if (redir) { 599 if (redir) {
600 if (n1->type != NSUBSHELL) { 600 if (n1 == NULL || n1->type != NSUBSHELL) {
601 n2 = stalloc(sizeof(struct nredir)); 601 n2 = stalloc(sizeof(struct nredir));
602 n2->type = NREDIR; 602 n2->type = NREDIR;
603 n2->nredir.n = n1; 603 n2->nredir.n = n1;
604 n1 = n2; 604 n1 = n2;
605 } 605 }
606 n1->nredir.redirect = redir; 606 n1->nredir.redirect = redir;
607 } 607 }
608 608
609 checkneg: 609 checkneg:
610#ifdef BOGUS_NOT_COMMAND 610#ifdef BOGUS_NOT_COMMAND
611 if (negate) { 611 if (negate) {
612 VTRACE(DBG_PARSE, ("bogus %snegate command\n", 612 VTRACE(DBG_PARSE, ("bogus %snegate command\n",
613 (negate&1) ? "" : "double ")); 613 (negate&1) ? "" : "double "));