Module Name: src Committed By: rillig Date: Fri Jul 31 07:29:21 UTC 2020
Modified Files: src/usr.bin/make: Makefile var.c src/usr.bin/make/unit-tests: moderrs.exp Log Message: make(1): fix undefined behavior in malformed :S modifier The unit tests failed on Ubuntu, and by looking closely at the code, it was trivial to see the out-of-bounds memory read. Other modifiers may have the same problem and will be inspected later. To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/usr.bin/make/Makefile cvs rdiff -u -r1.358 -r1.359 src/usr.bin/make/var.c cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/moderrs.exp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/Makefile diff -u src/usr.bin/make/Makefile:1.76 src/usr.bin/make/Makefile:1.77 --- src/usr.bin/make/Makefile:1.76 Wed Jul 29 20:57:31 2020 +++ src/usr.bin/make/Makefile Fri Jul 31 07:29:21 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.76 2020/07/29 20:57:31 rillig Exp $ +# $NetBSD: Makefile,v 1.77 2020/07/31 07:29:21 rillig Exp $ # @(#)Makefile 5.2 (Berkeley) 12/28/90 PROG= make @@ -8,11 +8,17 @@ SRCS+= str.c strlist.c suff.c targ.c tra USE_COVERAGE?= no # works only with gcc; clang9 fails to link .if ${USE_COVERAGE} == "yes" -COPTS= --coverage -O0 -ggdb -LDADD= --coverage +COPTS+= --coverage -O0 -ggdb +LDADD+= --coverage CLEANFILES+= ${SRCS:.c=.gcda} ${SRCS:.c=.gcno} ${SRCS:=.gcov} .endif +USE_UBSAN?= no +.if ${USE_UBSAN} == "yes" +COPTS+= -fsanitize=undefined +LDADD+= -fsanitize=undefined +.endif + USE_META?= yes .if ${USE_META:tl} != "no" Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.358 src/usr.bin/make/var.c:1.359 --- src/usr.bin/make/var.c:1.358 Wed Jul 29 21:35:35 2020 +++ src/usr.bin/make/var.c Fri Jul 31 07:29:21 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.358 2020/07/29 21:35:35 rillig Exp $ */ +/* $NetBSD: var.c,v 1.359 2020/07/31 07:29:21 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.358 2020/07/29 21:35:35 rillig Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.359 2020/07/31 07:29:21 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.358 2020/07/29 21:35:35 rillig Exp $"); +__RCSID("$NetBSD: var.c,v 1.359 2020/07/31 07:29:21 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -2395,6 +2395,11 @@ ApplyModifier_Subst(const char * const m ModifyWord_SubstArgs args; Boolean oneBigWord = st->oneBigWord; char delim = mod[1]; + if (delim == '\0') { + Error("Missing delimiter for :S modifier"); + st->next = mod + 1; + return AMR_CLEANUP; + } st->next = mod + 2; Index: src/usr.bin/make/unit-tests/moderrs.exp diff -u src/usr.bin/make/unit-tests/moderrs.exp:1.9 src/usr.bin/make/unit-tests/moderrs.exp:1.10 --- src/usr.bin/make/unit-tests/moderrs.exp:1.9 Wed Jul 29 20:33:38 2020 +++ src/usr.bin/make/unit-tests/moderrs.exp Fri Jul 31 07:29:21 2020 @@ -36,7 +36,7 @@ make: Unclosed substitution for VARNAME make: Unclosed substitution for ! (! missing) mod-subst-delimiter: -make: Unclosed substitution for VAR (@ missing) +make: Missing delimiter for :S modifier make: Unclosed substitution for VAR (, missing) @@ -49,8 +49,8 @@ make: Unclosed substitution for VAR (, m make: Unclosed variable specification (expecting '}') for "VAR" (value "TheVariable") modifier S TheVariable TheVariable -make: Unclosed variable specification (expecting '}') for "VAR" (value "TheVariable") modifier S -1: TheVariable +make: Missing delimiter for :S modifier +1: make: Unclosed substitution for VAR (, missing) 2: make: Unclosed substitution for VAR (, missing)