Module Name: src
Committed By: rillig
Date: Sun Jun 2 11:25:04 UTC 2024
Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod.exp varmod.mk
Log Message:
make: fix out-of-bounds read when parsing indirect modifiers
To generate a diff of this commit:
cvs rdiff -u -r1.1117 -r1.1118 src/usr.bin/make/var.c
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/varmod.exp
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/varmod.mk
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/var.c
diff -u src/usr.bin/make/var.c:1.1117 src/usr.bin/make/var.c:1.1118
--- src/usr.bin/make/var.c:1.1117 Sat Jun 1 06:26:36 2024
+++ src/usr.bin/make/var.c Sun Jun 2 11:25:03 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1117 2024/06/01 06:26:36 sjg Exp $ */
+/* $NetBSD: var.c,v 1.1118 2024/06/02 11:25:03 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -132,7 +132,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1117 2024/06/01 06:26:36 sjg Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1118 2024/06/02 11:25:03 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -2083,7 +2083,7 @@ static bool
IsEscapedModifierPart(const char *p, char delim,
struct ModifyWord_SubstArgs *subst)
{
- if (p[0] != '\\')
+ if (p[0] != '\\' || p[1] == '\0')
return false;
if (p[1] == delim || p[1] == '\\' || p[1] == '$')
return true;
Index: src/usr.bin/make/unit-tests/varmod.exp
diff -u src/usr.bin/make/unit-tests/varmod.exp:1.10 src/usr.bin/make/unit-tests/varmod.exp:1.11
--- src/usr.bin/make/unit-tests/varmod.exp:1.10 Sat Jun 1 18:44:05 2024
+++ src/usr.bin/make/unit-tests/varmod.exp Sun Jun 2 11:25:03 2024
@@ -9,6 +9,8 @@ make: Bad modifier ":[2147483648]" for v
make: "varmod.mk" line 128: Malformed conditional (${word:L:[2147483648]})
make: "varmod.mk" line 135: while evaluating variable "word": Invalid number "99333000222000111000}" for ':range' modifier
make: "varmod.mk" line 135: Malformed conditional (${word:L:range=99333000222000111000})
+make: "varmod.mk" line 143: while evaluating "${:${:Ugmtime=\\}}": Invalid time value "\"
+make: "varmod.mk" line 143: Malformed conditional (${:${:Ugmtime=\\}})
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
Index: src/usr.bin/make/unit-tests/varmod.mk
diff -u src/usr.bin/make/unit-tests/varmod.mk:1.12 src/usr.bin/make/unit-tests/varmod.mk:1.13
--- src/usr.bin/make/unit-tests/varmod.mk:1.12 Sat Jun 1 18:44:05 2024
+++ src/usr.bin/make/unit-tests/varmod.mk Sun Jun 2 11:25:03 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod.mk,v 1.12 2024/06/01 18:44:05 rillig Exp $
+# $NetBSD: varmod.mk,v 1.13 2024/06/02 11:25:03 rillig Exp $
#
# Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback.
#
@@ -134,3 +134,12 @@ VAR= STOP
# expect+1: while evaluating variable "word": Invalid number "99333000222000111000}" for ':range' modifier
.if ${word:L:range=99333000222000111000}
.endif
+
+# In an indirect modifier, the delimiter is '\0', which at the same time marks
+# the end of the string. The sequence '\\' '\0' is not an escaped delimiter,
+# as it would be wrong to skip past the end of the string.
+# expect+2: while evaluating "${:${:Ugmtime=\\}}": Invalid time value "\"
+# expect+1: Malformed conditional (${:${:Ugmtime=\\}})
+.if ${:${:Ugmtime=\\}}
+. error
+.endif