Explorar el Código

ci(fuzz): Add fuzzing for base64 encoding and decoding

Stefan Profanter hace 5 años
padre
commit
0f1192c99a
Se han modificado 3 ficheros con 49 adiciones y 0 borrados
  1. 3 0
      tests/fuzz/CMakeLists.txt
  2. 23 0
      tests/fuzz/fuzz_base64_decode.cc
  3. 23 0
      tests/fuzz/fuzz_base64_encode.cc

+ 3 - 0
tests/fuzz/CMakeLists.txt

@@ -104,6 +104,9 @@ add_fuzzer(fuzz_mdns_message ${PROJECT_SOURCE_DIR}/deps/mdnsd/tests/fuzz/fuzz_md
 add_fuzzer(fuzz_mdns_xht ${PROJECT_SOURCE_DIR}/deps/mdnsd/tests/fuzz/fuzz_mdns_xht.cc)
 
 
+add_fuzzer(fuzz_base64_encode fuzz_base64_encode.cc)
+add_fuzzer(fuzz_base64_decode fuzz_base64_decode.cc)
+
 if(UA_ENABLE_JSON_ENCODING)
     add_fuzzer(fuzz_json_decode fuzz_json_decode.cc)
     add_fuzzer(fuzz_json_decode_encode fuzz_json_decode_encode.cc)

+ 23 - 0
tests/fuzz/fuzz_base64_decode.cc

@@ -0,0 +1,23 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ *    Copyright 2019 (c) fortiss (Author: Stefan Profanter)
+ */
+
+
+
+/*
+** Main entry point.  The fuzzer invokes this function with each
+** fuzzed input.
+*/
+#include <base64.h>
+
+extern "C" int
+LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
+    size_t retLen;
+    unsigned char* ret = UA_unbase64(data, size, &retLen);
+    if (retLen > 0)
+        free(ret);
+    return 0;
+}

+ 23 - 0
tests/fuzz/fuzz_base64_encode.cc

@@ -0,0 +1,23 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ *    Copyright 2019 (c) fortiss (Author: Stefan Profanter)
+ */
+
+
+
+/*
+** Main entry point.  The fuzzer invokes this function with each
+** fuzzed input.
+*/
+#include <base64.h>
+
+extern "C" int
+LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
+    size_t retLen;
+    unsigned char* ret = UA_base64(data, size, &retLen);
+    if (retLen > 0)
+        free(ret);
+    return 0;
+}