diff options
| author | rillig <rillig@NetBSD.org> | 2020-08-22 21:12:29 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2020-08-22 21:12:29 +0000 |
| commit | 7c577f49cf0822dff76c7e8cd2e94e8fbd757fd9 (patch) | |
| tree | 4ae7165a789f73237e92afc8a14a958bbc3c7b61 /usr.bin/make | |
| parent | a20c3fcd7986fee8017f393c6fafc2e8e82ca591 (diff) | |
make(1): fix undefined behavior when assigning to variable ""
Using a programming language with built-in array bounds checks would
have prevented this bug, and many others as well.
Diffstat (limited to 'usr.bin/make')
| -rw-r--r-- | usr.bin/make/parse.c | 8 | ||||
| -rw-r--r-- | usr.bin/make/unit-tests/varname-empty.mk | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index 2b1eda4ba65..d16590b74b5 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.258 2020/08/22 17:34:25 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.259 2020/08/22 21:12:29 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: parse.c,v 1.258 2020/08/22 17:34:25 rillig Exp $"; +static char rcsid[] = "$NetBSD: parse.c,v 1.259 2020/08/22 21:12:29 rillig Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: parse.c,v 1.258 2020/08/22 17:34:25 rillig Exp $"); +__RCSID("$NetBSD: parse.c,v 1.259 2020/08/22 21:12:29 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -1876,7 +1876,7 @@ Parse_DoVar(char *line, GNode *ctxt) * XXX Rather than counting () and {} we should look for $ and * then expand the variable. */ - for (depth = 0, cp = line + 1; depth > 0 || *cp != '='; cp++) { + for (depth = 0, cp = line; depth > 0 || *cp != '='; cp++) { if (*cp == '(' || *cp == '{') { depth++; continue; diff --git a/usr.bin/make/unit-tests/varname-empty.mk b/usr.bin/make/unit-tests/varname-empty.mk index 2bced2fdc32..87de6ab0922 100644 --- a/usr.bin/make/unit-tests/varname-empty.mk +++ b/usr.bin/make/unit-tests/varname-empty.mk @@ -1,4 +1,4 @@ -# $NetBSD: varname-empty.mk,v 1.3 2020/08/22 21:02:56 rillig Exp $ +# $NetBSD: varname-empty.mk,v 1.4 2020/08/22 21:12:29 rillig Exp $ # # Tests for the special variable with the empty name. # @@ -9,7 +9,7 @@ # Until 2020-08-22 it was possible to assign a value to the variable with # the empty name, leading to all kinds of unexpected effects. ?= default -#= assigned # XXX: probably undefined behavior += assigned # undefined behavior until 2020-08-22 += appended := subst != echo 'value' |
