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 = |
| 17 SEC_ASN1_GET(SEC_GeneralizedTimeTemplate); |
| 18 SECItem quick_dest = {siBuffer, nullptr, 0}; |
| 19 SECItem legacy_dest = {siBuffer, nullptr, 0}; |
| 20 |
| 21 // Attempt the QuickDER path. |
| 22 PLArenaPool* quick_arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
| 23 if (!quick_arena) |
| 24 return 0; |
| 25 |
| 26 SECItem quick_src = {siBuffer, const_cast<unsigned char*>( |
| 27 static_cast<const unsigned char*>(data)), |
| 28 static_cast<unsigned int>(size)}; |
| 29 SEC_QuickDERDecodeItem(quick_arena, &quick_dest, the_template, &quick_src); |
| 30 PORT_FreeArena(quick_arena, PR_FALSE); |
| 31 |
| 32 // Attempt the Legacy path. |
| 33 PLArenaPool* legacy_arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
| 34 if (!legacy_arena) |
| 35 return 0; |
| 36 |
| 37 SECItem legacy_src = {siBuffer, const_cast<unsigned char*>( |
| 38 static_cast<const unsigned char*>(data)), |
| 39 static_cast<unsigned int>(size)}; |
| 40 |
| 41 SEC_ASN1DecodeItem(legacy_arena, &legacy_dest, the_template, &legacy_src); |
| 42 PORT_FreeArena(legacy_arena, PR_FALSE); |
| 43 |
| 44 return 0; |
| 45 } |
OLD | NEW |