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 <nss.h> |
| 9 #include <nspr.h> |
| 10 #include <secasn1.h> |
| 11 #include <secder.h> |
| 12 #include <secport.h> |
| 13 |
| 14 // Entry point for LibFuzzer. |
| 15 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 16 const SEC_ASN1Template* the_template = SEC_ASN1_GET(SEC_BMPStringTemplate); |
| 17 SECItem quick_dest = {siBuffer, nullptr, 0}; |
| 18 SECItem legacy_dest = {siBuffer, nullptr, 0}; |
| 19 |
| 20 // Attempt the QuickDER path. |
| 21 PLArenaPool* quick_arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
| 22 if (!quick_arena) |
| 23 return 0; |
| 24 |
| 25 SECItem quick_src = {siBuffer, const_cast<unsigned char*>( |
| 26 static_cast<const unsigned char*>(data)), |
| 27 static_cast<unsigned int>(size)}; |
| 28 SEC_QuickDERDecodeItem(quick_arena, &quick_dest, the_template, &quick_src); |
| 29 PORT_FreeArena(quick_arena, PR_FALSE); |
| 30 |
| 31 // Attempt the Legacy path. |
| 32 PLArenaPool* legacy_arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
| 33 if (!legacy_arena) |
| 34 return 0; |
| 35 |
| 36 SECItem legacy_src = {siBuffer, const_cast<unsigned char*>( |
| 37 static_cast<const unsigned char*>(data)), |
| 38 static_cast<unsigned int>(size)}; |
| 39 |
| 40 SEC_ASN1DecodeItem(legacy_arena, &legacy_dest, the_template, &legacy_src); |
| 41 PORT_FreeArena(legacy_arena, PR_FALSE); |
| 42 |
| 43 return 0; |
| 44 } |
OLD | NEW |