1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #include <string>
6 
7 #include "shared.h"
8 
9 #define TEST_FUNCTION(f) \
10   out = f(certName);     \
11   free(out);
12 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
14   std::string name(data, data + size);
15 
16   assert(SECOID_Init() == SECSuccess);
17 
18   CERTName* certName = CERT_AsciiToName(name.c_str());
19   if (certName) {
20     char* out;
21     TEST_FUNCTION(CERT_NameToAscii)
22     TEST_FUNCTION(CERT_GetCertEmailAddress)
23 
24     // These functions call CERT_GetNameElement with different OIDs.
25     // Unfotunately CERT_GetNameElement is not accesible from here.
26     TEST_FUNCTION(CERT_GetCertUid)
27     TEST_FUNCTION(CERT_GetCommonName)
28     TEST_FUNCTION(CERT_GetCountryName)
29     TEST_FUNCTION(CERT_GetDomainComponentName)
30     TEST_FUNCTION(CERT_GetLocalityName)
31     TEST_FUNCTION(CERT_GetOrgName)
32     TEST_FUNCTION(CERT_GetOrgUnitName)
33     TEST_FUNCTION(CERT_GetStateName)
34 
35     out = CERT_NameToAsciiInvertible(certName, CERT_N2A_READABLE);
36     free(out);
37     out = CERT_NameToAsciiInvertible(certName, CERT_N2A_STRICT);
38     free(out);
39     out = CERT_NameToAsciiInvertible(certName, CERT_N2A_INVERTIBLE);
40     free(out);
41   }
42   CERT_DestroyName(certName);
43 
44   return 0;
45 }
46