Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make/unit-tests make(1): add test for intentional ha...
details: https://anonhg.NetBSD.org/src/rev/4c65b57829df
branches: trunk
changeset: 943512:4c65b57829df
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Sep 05 12:59:07 2020 +0000
description:
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.
diffstat:
usr.bin/make/unit-tests/Makefile | 3 +-
usr.bin/make/unit-tests/varname.mk | 41 +++++++++++++++++++++++++++++++++++--
2 files changed, 40 insertions(+), 4 deletions(-)
diffs (67 lines):
diff -r d186eee2028a -r 4c65b57829df usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile Sat Sep 05 12:19:25 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile Sat Sep 05 12:59:07 2020 +0000
@@ -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 @@
${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'
diff -r d186eee2028a -r 4c65b57829df usr.bin/make/unit-tests/varname.mk
--- a/usr.bin/make/unit-tests/varname.mk Sat Sep 05 12:19:25 2020 +0000
+++ b/usr.bin/make/unit-tests/varname.mk Sat Sep 05 12:59:07 2020 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index