Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1467)

Unified Diff: testing/libfuzzer/fuzzers/nss/asn1_fuzzer_template.h

Issue 1677803002: Add a bunch of NSS ASN.1 fuzzers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix leak Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: testing/libfuzzer/fuzzers/nss/asn1_fuzzer_template.h
diff --git a/testing/libfuzzer/fuzzers/nss/asn1_fuzzer_template.h b/testing/libfuzzer/fuzzers/nss/asn1_fuzzer_template.h
new file mode 100644
index 0000000000000000000000000000000000000000..416b707ec48d15bd5227d7d46c2b616891ffcbef
--- /dev/null
+++ b/testing/libfuzzer/fuzzers/nss/asn1_fuzzer_template.h
@@ -0,0 +1,45 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASN1_FUZZER_TEMPLATE_H_
+#define ASN1_FUZZER_TEMPLATE_H_
+
+#include <nspr.h>
+#include <nss.h>
+#include <secasn1.h>
+#include <secder.h>
+#include <secitem.h>
+#include <secport.h>
+#include <stddef.h>
+#include <stdint.h>
+
+template <typename DestinationType,
+ SECStatus (*DecodeFunction)(PLArenaPool*,
+ void*,
+ const SEC_ASN1Template*,
+ const SECItem*)>
+void NSSFuzzOneInput(const SEC_ASN1Template* the_template,
+ const uint8_t* data,
+ size_t size) {
+ DestinationType* destination = new DestinationType();
+ memset(destination, 0, sizeof(DestinationType));
+
+ PLArenaPool* arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
+ if (!arena) {
+ delete destination;
+ return;
+ }
+
+ SECItem source;
+ source.type = siBuffer;
+ source.data = static_cast<unsigned char*>(const_cast<uint8_t*>(data));
+ source.len = static_cast<unsigned int>(size);
+
+ DecodeFunction(arena, destination, the_template, &source);
+
+ PORT_FreeArena(arena, PR_FALSE);
+ delete destination;
+}
+
+#endif // ASN1_FUZZER_TEMPLATE_H_

Powered by Google App Engine
This is Rietveld 408576698