OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 8 #include <cert.h> |
| 9 #include <nss.h> |
| 10 #include <nspr.h> |
| 11 #include <secasn1.h> |
| 12 #include <secder.h> |
| 13 #include <secport.h> |
| 14 |
| 15 // Entry point for LibFuzzer. |
| 16 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 17 const SEC_ASN1Template* the_template = SEC_ASN1_GET(CERT_CertificateTemplate); |
| 18 CERTCertificate quick_dest_local; |
| 19 memset(&quick_dest_local, 0, sizeof(quick_dest_local)); |
| 20 CERTCertificate* quick_dest = &quick_dest_local; |
| 21 |
| 22 CERTCertificate legacy_dest_local; |
| 23 memset(&legacy_dest_local, 0, sizeof(legacy_dest_local)); |
| 24 CERTCertificate* legacy_dest = &legacy_dest_local; |
| 25 |
| 26 // Attempt the QuickDER path. |
| 27 PLArenaPool* quick_arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
| 28 if (!quick_arena) |
| 29 return 0; |
| 30 |
| 31 SECItem quick_src = {siBuffer, const_cast<unsigned char*>( |
| 32 static_cast<const unsigned char*>(data)), |
| 33 static_cast<unsigned int>(size)}; |
| 34 SEC_QuickDERDecodeItem(quick_arena, &quick_dest, the_template, &quick_src); |
| 35 PORT_FreeArena(quick_arena, PR_FALSE); |
| 36 |
| 37 // Attempt the Legacy path. |
| 38 PLArenaPool* legacy_arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
| 39 if (!legacy_arena) |
| 40 return 0; |
| 41 |
| 42 SECItem legacy_src = {siBuffer, const_cast<unsigned char*>( |
| 43 static_cast<const unsigned char*>(data)), |
| 44 static_cast<unsigned int>(size)}; |
| 45 |
| 46 SEC_ASN1DecodeItem(legacy_arena, &legacy_dest, the_template, &legacy_src); |
| 47 PORT_FreeArena(legacy_arena, PR_FALSE); |
| 48 |
| 49 return 0; |
| 50 } |
OLD | NEW |