Module Name: src
Committed By: rillig
Date: Sat Sep 5 12:59:07 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: Makefile varname.mk
Log Message:
make(1): add test for intentional hash collision for variable names
Hash collisions may slow down make in certain special situations. There
is no point though in maliciously triggering such a situation since
anyone who can inject values into makefiles can easily run shell
commands using the :!cmd! modifier or similar mechanisms. Crafting
variable names just to slow down make is thus not an attack vector.
To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varname.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/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.135 src/usr.bin/make/unit-tests/Makefile:1.136
--- src/usr.bin/make/unit-tests/Makefile:1.135 Sat Sep 5 06:36:40 2020
+++ src/usr.bin/make/unit-tests/Makefile Sat Sep 5 12:59:07 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.135 2020/09/05 06:36:40 rillig Exp $
+# $NetBSD: Makefile,v 1.136 2020/09/05 12:59:07 rillig Exp $
#
# Unit tests for make(1)
#
@@ -393,6 +393,7 @@ POSTPROC.deptgt-suffixes= \
${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
+POSTPROC.varname= ${TOOL_SED} -n -e '/^MAGIC/p' -e '/^ORDER_/p'
POSTPROC.varname-dot-shell= \
awk '/\.SHELL/ || /^ParseReadLine/'
POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
Index: src/usr.bin/make/unit-tests/varname.mk
diff -u src/usr.bin/make/unit-tests/varname.mk:1.2 src/usr.bin/make/unit-tests/varname.mk:1.3
--- src/usr.bin/make/unit-tests/varname.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varname.mk Sat Sep 5 12:59:07 2020
@@ -1,8 +1,43 @@
-# $NetBSD: varname.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname.mk,v 1.3 2020/09/05 12:59:07 rillig Exp $
#
# Tests for special variables, such as .MAKE or .PARSEDIR.
-# TODO: Implementation
+# These following MAGIC variables have the same hash code, at least with
+# the default hashing algorithm, which is the same as in Java. The order
+# in which these variables are defined determines the order in which they
+# appear in the Hash_Table. New entries are prepended to the bucket lists,
+# therefore this test numbers the values in descending order.
+
+.if defined(ORDER_01)
+
+MAGIC0a0a0a= 8
+MAGIC0a0a1B= 7
+MAGIC0a1B0a= 6
+MAGIC0a1B1B= 5
+MAGIC1B0a0a= 4
+MAGIC1B0a1B= 3
+MAGIC1B1B0a= 2
+MAGIC1B1B1B= 1
+
+all: # nothing
+
+.elif defined(ORDER_10)
+
+MAGIC1B1B1B= 8
+MAGIC1B1B0a= 7
+MAGIC1B0a1B= 6
+MAGIC1B0a0a= 5
+MAGIC0a1B1B= 4
+MAGIC0a1B0a= 3
+MAGIC0a0a1B= 2
+MAGIC0a0a0a= 1
+
+all: # nothing
+
+.else
all:
- @:;
+ @${.MAKE} -f ${MAKEFILE} -dg1 ORDER_01=yes
+ @${.MAKE} -f ${MAKEFILE} -dg1 ORDER_10=yes
+
+.endif