Fix alignment errors in hashtable fuzzer
authorNeil Horman <nhorman@openssl.org>
Fri, 26 Apr 2024 16:38:38 +0000 (12:38 -0400)
committerTomas Mraz <tomas@openssl.org>
Tue, 30 Apr 2024 10:53:51 +0000 (12:53 +0200)
we extract several values (uint16_t and uint64_t from the fuzzer buff
passed in, but they weren't aligned on 2 and 8 byte boundaries.  Adjust
the fuzzer to memcpy data to the target variables to avoid unalignment
issues

Fixes #24272

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24276)

fuzz/hashtable.c

index 64a736d81519353ed23385661fdd0d6d56d6bd5e..35cf9c8f3ba74832f984f7379e122285d1ba3cb4 100644 (file)
@@ -142,7 +142,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
      * parse out our operation flags and key
      */
     op_flags = buf[0];
-    keyval = *((uint16_t *)&buf[1]);
+    memcpy(&keyval, &buf[1], sizeof(uint16_t));
 
     /*
      * Initialize our key
@@ -177,7 +177,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
                 rc_prediction = 0;
         }
 
-        valptr->value = *(uint64_t *)&buf[3];
+        memcpy(&valptr->value, &buf[3], sizeof(uint64_t));
         /*
          * do the insert/replace
          */