• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "formutil_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <fuzzer/FuzzedDataProvider.h>
21 
22 #include "form_constants.h"
23 #define private public
24 #define protected public
25 #include "feature/free_install/free_install_status_callback_proxy.h"
26 #include "feature/free_install/free_install_status_callback_stub.h"
27 #include "common/util/form_util.h"
28 #undef private
29 #undef protected
30 #include "securec.h"
31 
32 using namespace OHOS::AppExecFwk;
33 
34 namespace OHOS {
35 class FreeInstallStatusCallBackStubFuzzTest : public FreeInstallStatusCallBackStub {
36 public:
37     FreeInstallStatusCallBackStubFuzzTest() = default;
38     virtual ~FreeInstallStatusCallBackStubFuzzTest() = default;
OnInstallFinished(int32_t resultCode,const Want & want,int32_t userId)39     void OnInstallFinished(int32_t resultCode, const Want &want, int32_t userId) override
40     {}
41 };
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)42 bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp)
43 {
44     if (fdp == nullptr) {
45         return true;
46     }
47     FormUtil formUtil;
48     std::string formName = fdp->ConsumeRandomLengthString();
49     int32_t specificationId = fdp->ConsumeIntegral<int32_t>();
50     bool isTemporaryForm = fdp->ConsumeBool();
51     Want want;
52     want.SetParam(Constants::PARAM_FORM_NAME_KEY, formName);
53     want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, specificationId);
54     want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, isTemporaryForm);
55     std::string uri = fdp->ConsumeRandomLengthString();
56     int32_t connectId = fdp->ConsumeIntegral<int32_t>();
57     want.SetParam(Constants::FORM_CONNECT_ID, connectId);
58     want.SetParam(Constants::FORM_SUPPLY_INFO, uri);
59     int64_t udidHash = fdp->ConsumeIntegral<int64_t>();
60     formUtil.GenerateFormId(udidHash);
61     uint64_t formId = fdp->ConsumeIntegral<uint64_t>();
62     uint64_t udidHashs = fdp->ConsumeIntegral<uint64_t>();
63     formUtil.PaddingUdidHash(formId, udidHashs);
64     formUtil.GetCurrentNanosecond();
65     formUtil.GetCurrentMillisecond();
66     formUtil.GetCurrentAccountId();
67     formUtil.GetNowMillisecond();
68     formUtil.DeleteFormId(udidHash);
69     int radix = fdp->ConsumeIntegral<int>();
70     formUtil.ConvertStringToInt(formName, radix);
71     formUtil.ConvertStringToLongLong(formName, radix);
72     std::string strInfo = fdp->ConsumeRandomLengthString();
73     int64_t convertValue = fdp->ConsumeIntegral<int64_t>();
74     formUtil.ConvertStringToInt64(strInfo, convertValue);
75     sptr<IRemoteObject> impl = nullptr;
76     FreeInstallStatusCallBackProxy freeInstallStatusCallBackProxy(impl);
77     FreeInstallStatusCallBackStubFuzzTest freeInstallStatusCallBackStubFuzzTest;
78     MessageParcel datas;
79     MessageParcel reply;
80     freeInstallStatusCallBackStubFuzzTest.OnInstallFinishedInner(datas, reply);
81     uint32_t code = fdp->ConsumeIntegral<uint32_t>();
82     MessageOption option;
83     freeInstallStatusCallBackStubFuzzTest.OnRemoteRequest(code, datas, reply, option);
84     return formUtil.GenerateUdidHash(udidHash);
85 }
86 }
87 
88 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)89 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
90 {
91     FuzzedDataProvider fdp(data, size);
92     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
93     return 0;
94 }