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