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