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 segfault when evaluating ${::=value}



details:   https://anonhg.NetBSD.org/src/rev/7f77f3b3ba33
branches:  trunk
changeset: 936549:7f77f3b3ba33
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jul 29 20:33:38 2020 +0000

description:
make(1): fix segfault when evaluating ${::=value}

The bug had been in the handling of the SysV modifier for many years, but
it had not been triggered since the "parsing position for the next
modifier" had been initialized to a non-NULL pointer.

In var.v r1.350, this pointer had been initialized to NULL instead since
every ApplyModifier function must set it in every case where it returns
anything except "default_case".

There might have been a slight chance of tricking make to output a wrong
error message, but nothing worse.

diffstat:

 usr.bin/make/unit-tests/moderrs.exp |   2 ++
 usr.bin/make/unit-tests/moderrs.mk  |   6 ++----
 usr.bin/make/var.c                  |  13 ++++++++-----
 3 files changed, 12 insertions(+), 9 deletions(-)

diffs (87 lines):

diff -r 94d89423af62 -r 7f77f3b3ba33 usr.bin/make/unit-tests/moderrs.exp
--- a/usr.bin/make/unit-tests/moderrs.exp       Wed Jul 29 19:48:33 2020 +0000
+++ b/usr.bin/make/unit-tests/moderrs.exp       Wed Jul 29 20:33:38 2020 +0000
@@ -117,6 +117,8 @@
 mod-assign-parse:
 make: Unknown modifier ':'
 
+make: Bad modifier `:' for 
+value}
 make: Unclosed substitution for ASSIGN (} missing)
 
 mod-remember-parse:
diff -r 94d89423af62 -r 7f77f3b3ba33 usr.bin/make/unit-tests/moderrs.mk
--- a/usr.bin/make/unit-tests/moderrs.mk        Wed Jul 29 19:48:33 2020 +0000
+++ b/usr.bin/make/unit-tests/moderrs.mk        Wed Jul 29 20:33:38 2020 +0000
@@ -1,4 +1,4 @@
-# $Id: moderrs.mk,v 1.7 2020/07/29 19:48:33 rillig Exp $
+# $Id: moderrs.mk,v 1.8 2020/07/29 20:33:38 rillig Exp $
 #
 # various modifier error tests
 
@@ -151,9 +151,7 @@
 mod-assign-parse:
        @echo $@:
        @echo ${ASSIGN::x}      # 'x' is an unknown assignment operator
-# disabled for now; segfaults on NetBSD-8.0-x86_64 in Var_Parse line 3636:
-# *lengthPtr = tstr - str + (*tstr ? 1 : 0);
-#      @echo ${::=value}       # trying to set the empty variable
+       @echo ${::=value}       # trying to set the empty variable
        @echo ${ASSIGN::=value  # missing closing brace
 
 mod-remember-parse:
diff -r 94d89423af62 -r 7f77f3b3ba33 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Wed Jul 29 19:48:33 2020 +0000
+++ b/usr.bin/make/var.c        Wed Jul 29 20:33:38 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.354 2020/07/29 19:48:33 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.355 2020/07/29 20:33:38 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.354 2020/07/29 19:48:33 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.355 2020/07/29 20:33:38 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.354 2020/07/29 19:48:33 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.355 2020/07/29 20:33:38 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2575,7 +2575,7 @@
 static Boolean
 ApplyModifier_To(const char *mod, ApplyModifiersState *st)
 {
-    st->next = mod + 1;        /* make sure it is set */
+    st->next = mod + 1;                /* make sure it is set */
     if (mod[1] == st->endc || mod[1] == ':')
        return FALSE;           /* Found ":t<endc>" or ":t:". */
 
@@ -2818,8 +2818,10 @@
 
     GNode *v_ctxt;             /* context where v belongs */
 
-    if (st->v->name[0] == 0)
+    if (st->v->name[0] == 0) {
+       st->next = mod + 1;
        return 'b';
+    }
 
     v_ctxt = st->ctxt;
     char *sv_name = NULL;
@@ -3117,6 +3119,7 @@
        }
        st.newVal = var_Error;
        char modifier = *p;
+       st.next = NULL; /* fail fast if an ApplyModifier forgets to set this */
        switch (modifier) {
        case ':':
            {



Home | Main Index | Thread Index | Old Index