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 parsing ma...



details:   https://anonhg.NetBSD.org/src/rev/db6a38858587
branches:  trunk
changeset: 936577:db6a38858587
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 31 13:30:09 2020 +0000

description:
make(1): fix undefined behavior when parsing malformed :C modifier

Same as in the :S modifier.

diffstat:

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

diffs (79 lines):

diff -r 31883f63f119 -r db6a38858587 usr.bin/make/unit-tests/moderrs.exp
--- a/usr.bin/make/unit-tests/moderrs.exp       Fri Jul 31 09:34:33 2020 +0000
+++ b/usr.bin/make/unit-tests/moderrs.exp       Fri Jul 31 13:30:09 2020 +0000
@@ -63,9 +63,8 @@
 TheVariable
 TheVariable
 mod-regex-delimiter:
-make: RE substitution error: (details omitted)
-make: Unclosed substitution for VAR (, missing)
-echo
+make: Missing delimiter for :C modifier
+
 make: Unclosed substitution for VAR (, missing)
 
 make: Unclosed substitution for VAR (, missing)
@@ -77,7 +76,7 @@
 make: Unclosed variable specification (expecting '}') for "VAR" (value "TheVariable") modifier C
 TheVariable
 TheVariable
-make: RE substitution error: (details omitted)
+make: Missing delimiter for :C modifier
 1:
 make: Unclosed substitution for VAR (, missing)
 2:
diff -r 31883f63f119 -r db6a38858587 usr.bin/make/unit-tests/moderrs.mk
--- a/usr.bin/make/unit-tests/moderrs.mk        Fri Jul 31 09:34:33 2020 +0000
+++ b/usr.bin/make/unit-tests/moderrs.mk        Fri Jul 31 13:30:09 2020 +0000
@@ -1,4 +1,4 @@
-# $Id: moderrs.mk,v 1.8 2020/07/29 20:33:38 rillig Exp $
+# $Id: moderrs.mk,v 1.9 2020/07/31 13:30:09 rillig Exp $
 #
 # various modifier error tests
 
@@ -109,7 +109,6 @@
        @echo ${VAR:S,from,to,
        @echo ${VAR:S,from,to,}
 
-# XXX: Where does the "echo" in the output of "${VAR:C" come from?
 mod-regex-delimiter:
        @echo $@:
        @echo ${VAR:C
diff -r 31883f63f119 -r db6a38858587 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Fri Jul 31 09:34:33 2020 +0000
+++ b/usr.bin/make/var.c        Fri Jul 31 13:30:09 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.359 2020/07/31 07:29:21 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.360 2020/07/31 13:30:09 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.359 2020/07/31 07:29:21 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.360 2020/07/31 13:30:09 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.359 2020/07/31 07:29:21 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.360 2020/07/31 13:30:09 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2468,6 +2468,11 @@
     args.pflags = 0;
     Boolean oneBigWord = st->oneBigWord;
     char delim = mod[1];
+    if (delim == '\0') {
+       Error("Missing delimiter for :C modifier");
+       st->next = mod + 1;
+       return AMR_CLEANUP;
+    }
 
     st->next = mod + 2;
 



Home | Main Index | Thread Index | Old Index