aboutsummaryrefslogtreecommitdiff
path: root/fuzz/xml_parse_fuzzer.c
diff options
context:
space:
mode:
Diffstat (limited to 'fuzz/xml_parse_fuzzer.c')
-rw-r--r--fuzz/xml_parse_fuzzer.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/fuzz/xml_parse_fuzzer.c b/fuzz/xml_parse_fuzzer.c
index 29ab33ff79d9..1eb0ad299628 100644
--- a/fuzz/xml_parse_fuzzer.c
+++ b/fuzz/xml_parse_fuzzer.c
@@ -17,6 +17,7 @@
#include <assert.h>
#include <limits.h> // for INT_MAX
#include <stdint.h>
+#include <string.h>
#include "expat.h"
#include "siphash.h"
@@ -34,7 +35,8 @@
#endif
// 16-byte deterministic hash key.
-static unsigned char hash_key[16] = "FUZZING IS FUN!";
+static unsigned char hash_key_1[16] = "FUZZING IS FUN?";
+static unsigned char hash_key_2[16] = "FUZZING IS FUN!";
static void XMLCALL
start(void *userData, const XML_Char *name, const XML_Char **atts) {
@@ -59,8 +61,14 @@ may_stop_character_handler(void *userData, const XML_Char *s, int len) {
static void
ParseOneInput(XML_Parser p, const uint8_t *data, size_t size) {
// Set the hash salt using siphash to generate a deterministic hash.
- struct sipkey *key = sip_keyof(hash_key);
- XML_SetHashSalt(p, (unsigned long)siphash24(data, size, key));
+ // The salt is 16 bytes and siphash24 produces 8, so the input is hashed
+ // under two keys.
+ const uint64_t first = siphash24(data, size, sip_keyof(hash_key_1));
+ const uint64_t second = siphash24(data, size, sip_keyof(hash_key_2));
+ uint8_t entropy[16];
+ memcpy(entropy, &first, sizeof(first));
+ memcpy(entropy + sizeof(first), &second, sizeof(second));
+ XML_SetHashSalt16Bytes(p, entropy);
(void)sip24_valid;
XML_SetUserData(p, p);