1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstddef>
17 #include <cstdint>
18 #include <cstdio>
19 #include "params_run_tool.h"
20
21 namespace OHOS {
22 namespace SignatureTools {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)23 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
24 {
25 if (!data || size <= 0) {
26 return true;
27 }
28
29 char arg0[] = "";
30 char arg1[] = "generate-keypair";
31 char arg2[] = "-keyAlias";
32 char* arg3 = new char[size];
33 memcpy_s(arg3, size, data, size);
34 char arg4[] = "-keyPwd";
35 char arg5[] = "123456";
36 char arg6[] = "-keyAlg";
37 char arg7[] = "ECC";
38 char arg8[] = "-keySize";
39 char arg9[] = "NIST-P-384";
40 char arg10[] = "-keystoreFile";
41 char arg11[] = "./generateKeyPair/OpenHarmonyTest.p12";
42 char arg12[] = "-keystorePwd";
43 char arg13[] = "123456";
44 char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13};
45
46 int argc = 14;
47
48 bool ret = ParamsRunTool::ProcessCmd(argv, argc);
49 delete[] arg3;
50 return ret;
51 }
52 } // namespace SignatureTools
53 } // namespace OHOS
54
55 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)56 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
57 {
58 /* Run your code on data */
59 OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size);
60 return 0;
61 }
62