Commit 2c83ba5a69 for bind
commit 2c83ba5a6984656f6098890739e82e90fb6a6b4e
Author: Michal Nowak <mnowak@isc.org>
Date: Thu Jun 4 11:55:39 2026 +0000
Make the dns_qp fuzzer keys collision-proof
The fuzzer assumes a one-to-one mapping between keys and items. In
fuzzing builds isc_random32() is a deterministic counter, so the
random key bytes can repeat and two items may share a key, which
trips the assert(pval == &item[i]) on the seed corpus. Encode the
item index into the first key bytes so the keys are always distinct.
Assisted-by: Claude:claude-opus-4-8
diff --git a/fuzz/dns_qp.c b/fuzz/dns_qp.c
index f0b70d260c..7adc39af07 100644
--- a/fuzz/dns_qp.c
+++ b/fuzz/dns_qp.c
@@ -102,6 +102,20 @@ LLVMFuzzerInitialize(int *argc, char ***argv) {
UNUSED(argc);
UNUSED(argv);
+ /*
+ * The fuzzer relies on a one-to-one mapping between keys and items.
+ * In fuzzing builds isc_random32() is a deterministic counter (see
+ * lib/isc/random.c), so the random bytes below can repeat and two
+ * items could end up with the same key. Encode the item index into
+ * the first key bytes to guarantee the keys are distinct; 3 key
+ * positions hold (SHIFT_OFFSET - SHIFT_NOBYTE) ^ 3 values each.
+ */
+ STATIC_ASSERT(ARRAY_SIZE(item) <=
+ (SHIFT_OFFSET - SHIFT_NOBYTE) *
+ (SHIFT_OFFSET - SHIFT_NOBYTE) *
+ (SHIFT_OFFSET - SHIFT_NOBYTE),
+ "item index does not fit in 3 key bytes");
+
for (size_t i = 0; i < ARRAY_SIZE(item); i++) {
size_t len = isc_random_uniform(100) + 16;
item[i].len = len + 1;
@@ -109,6 +123,12 @@ LLVMFuzzerInitialize(int *argc, char ***argv) {
for (size_t off = 1; off < len; off++) {
item[i].key[off] = random_byte();
}
+ uint32_t idx = i;
+ for (size_t off = 1; off <= 3; off++) {
+ item[i].key[off] = SHIFT_NOBYTE +
+ idx % (SHIFT_OFFSET - SHIFT_NOBYTE);
+ idx /= (SHIFT_OFFSET - SHIFT_NOBYTE);
+ }
memmove(item[i].ascii, item[i].key, item[i].len);
qp_test_keytoascii(item[i].ascii, item[i].len);
}