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 "updatecellulardata_fuzzer.h"
17
18 #define private public
19 #define protected public
20
21 #include "adddatatoken_fuzzer.h"
22 #include "cellular_data_dump_helper.h"
23 #include "cellular_data_handler.h"
24 #include "cellular_data_incall_observer.h"
25
26
27 namespace OHOS {
28 using namespace OHOS::Telephony;
29 using namespace AppExecFwk;
30 using namespace OHOS::EventFwk;
31
UpdateCellularDataDumpHelperFuzz(const uint8_t * data,size_t size)32 void UpdateCellularDataDumpHelperFuzz(const uint8_t *data, size_t size)
33 {
34 CellularDataDumpHelper help;
35 std::string arg(reinterpret_cast<const char*>(data), size);
36 std::vector<std::string> args;
37 args.emplace_back(arg);
38 std::string result;
39 help.Dump(args, result);
40 help.ShowHelp(result);
41 help.ShowCellularDataInfo(result);
42 std::shared_ptr<CellularDataHandler> cellularDataHandler = nullptr;
43 auto cellularDataIncallObserver = std::make_shared<CellularDataIncallObserver>(cellularDataHandler);
44 cellularDataIncallObserver->OnChange();
45 }
46
UpdateActiveMachineWithMyAPI(const uint8_t * data,size_t size)47 void UpdateActiveMachineWithMyAPI(const uint8_t *data, size_t size)
48 {
49 if (data == nullptr || size == 0) {
50 return;
51 }
52 UpdateCellularDataDumpHelperFuzz(data, size);
53 }
54 } // namespace OHOS
55
56 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
58 {
59 OHOS::AddDataTokenFuzzer token;
60 /* Run your code on data */
61 OHOS::UpdateActiveMachineWithMyAPI(data, size);
62 return 0;
63 }