Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): fix undefined behavior when assigning ...



details:   https://anonhg.NetBSD.org/src/rev/ca48041b9549
branches:  trunk
changeset: 937641:ca48041b9549
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 22 21:12:29 2020 +0000

description:
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:

 usr.bin/make/parse.c                     |  8 ++++----
 usr.bin/make/unit-tests/varname-empty.mk |  4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diffs (53 lines):

diff -r 3b93f98169b4 -r ca48041b9549 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Aug 22 21:02:56 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Aug 22 21:12:29 2020 +0000
@@ -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 @@
      * 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 -r 3b93f98169b4 -r ca48041b9549 usr.bin/make/unit-tests/varname-empty.mk
--- a/usr.bin/make/unit-tests/varname-empty.mk  Sat Aug 22 21:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/varname-empty.mk  Sat Aug 22 21:12:29 2020 +0000
@@ -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'



Home | Main Index | Thread Index | Old Index