summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hanselmann <public@hansmi.ch>2021-08-13 23:22:56 +0200
committerMichael Hanselmann <public@hansmi.ch>2021-08-13 23:22:56 +0200
commitd76f55afc59243b98e069e51ccd48770998423a8 (patch)
tree2ae2894973af879e1900a76194ef3055afb66e83
parent6ff5aa5050f87515d95fc458a4867cc13a3d1a4a (diff)
usbredirparserfuzz: Use constant for magic number
Now that the magic number for the serialization format is a header it can also be used for fuzzing. As it turned out I had gotten the endianess wrong in commit 58f198e and the unserialization code wasn't actually fuzzed (unless the fuzzer had somehow found the magic value). Endianess support is still in the TODO file and so a plain memcpy is sufficient. Signed-off-by: Michael Hanselmann <public@hansmi.ch>
-rw-r--r--fuzzing/usbredirparserfuzz.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/fuzzing/usbredirparserfuzz.cc b/fuzzing/usbredirparserfuzz.cc
index 6fb16c8..78073f3 100644
--- a/fuzzing/usbredirparserfuzz.cc
+++ b/fuzzing/usbredirparserfuzz.cc
@@ -20,6 +20,7 @@
#include <algorithm>
#include <memory>
+#include <cassert>
#include <cinttypes>
#include <cstring>
#include <limits>
@@ -255,9 +256,11 @@ int try_unserialize(struct usbredirparser *parser, FuzzedDataProvider *fdp)
state.reserve(len);
if (len >= 4) {
- // Could also move USBREDIRPARSER_SERIALIZE_MAGIC after moving it to
- // a shared header.
- state.insert(state.end(), {'U', 'R', 'P', '1'});
+ const uint32_t magic = USBREDIRPARSER_SERIALIZE_MAGIC;
+ assert(state.empty());
+ state.resize(sizeof(magic));
+ memcpy(state.data(), &magic, sizeof(magic));
+
len -= 4;
}