From 31d396587e83d6820aa1de3a2084f68d39d9fdaf Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sun, 13 Jan 2013 19:26:33 +0000 Subject: [PATCH] sh: Fix crash when parsing '{ } &'. MFC after: 1 week --- bin/sh/parser.c | 4 ++-- tools/regression/bin/sh/parser/empty-braces1.0 | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tools/regression/bin/sh/parser/empty-braces1.0 diff --git a/bin/sh/parser.c b/bin/sh/parser.c index a19ca3127bd3..665b53ff5aae 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -240,9 +240,9 @@ list(int nlflag, int erflag) n2 = andor(); tok = readtoken(); if (tok == TBACKGND) { - if (n2->type == NPIPE) { + if (n2 != NULL && n2->type == NPIPE) { n2->npipe.backgnd = 1; - } else if (n2->type == NREDIR) { + } else if (n2 != NULL && n2->type == NREDIR) { n2->type = NBACKGND; } else { n3 = (union node *)stalloc(sizeof (struct nredir)); diff --git a/tools/regression/bin/sh/parser/empty-braces1.0 b/tools/regression/bin/sh/parser/empty-braces1.0 new file mode 100644 index 000000000000..5ab443c48d8a --- /dev/null +++ b/tools/regression/bin/sh/parser/empty-braces1.0 @@ -0,0 +1,7 @@ +# $FreeBSD$ + +# Unfortunately, some scripts depend on the extension of allowing an empty +# pair of braces. + +{ } & +wait $!