From 9e255ef45c4928eb167c1f24756cb7ab435914e5 Mon Sep 17 00:00:00 2001 From: mstaib Date: Tue, 16 May 2017 21:41:39 +0200 Subject: Fix minor hashing bug in config_feature_flag configuration name. Previously, it was possible to have //package:foo : barbaz and //package:foobar : baz hash to the same value, making it very easy for users to cause a hash collision by accident. This adds a zero byte after each string so that the hash will differentiate the two. RELNOTES: None. PiperOrigin-RevId: 156216723 --- .../rules/config/ConfigFeatureFlagConfigurationTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/test/java/com/google/devtools/build/lib/rules/config') diff --git a/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagConfigurationTest.java b/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagConfigurationTest.java index a0de77dfdf..5034db2d25 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagConfigurationTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagConfigurationTest.java @@ -216,6 +216,20 @@ public final class ConfigFeatureFlagConfigurationTest { .isNotEqualTo(getConfigurationWithFlags(someFlags).getOutputDirectoryName()); } + @Test + public void getOutputDirectoryName_differentiatesLabelAndValue() throws Exception { + Map someFlags = + ImmutableMap.of( + Label.parseAbsoluteUnchecked("//a:a"), "firestarter", + Label.parseAbsoluteUnchecked("//b:b"), "second"); + Map otherFlags = + ImmutableMap.of( + Label.parseAbsoluteUnchecked("//a:afire"), "starter", + Label.parseAbsoluteUnchecked("//b:b"), "second"); + assertThat(getConfigurationWithFlags(otherFlags).getOutputDirectoryName()) + .isNotEqualTo(getConfigurationWithFlags(someFlags).getOutputDirectoryName()); + } + @Test public void getOutputDirectoryName_returnsDifferentValueForSubsetOfFlagValuePairs() throws Exception { -- cgit v1.2.3