1/*
2 * Copyright (c) 2023 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 "getservicectrlinfo_fuzzer.h"
17#include <string>
18#include "init_hook.h"
19#include "param_manager.h"
20
21#define NAME_LEN_MAX 96
22
23namespace OHOS {
24    bool FuzzGetServiceCtrlInfo(const uint8_t* data, size_t size)
25    {
26        if (size + sizeof("test") >= NAME_LEN_MAX) {
27            return false;
28        }
29
30        bool result = false;
31        ServiceCtrlInfo *serviceInfo = nullptr;
32        GetServiceCtrlInfo("ohos.ctl.stop", "test", &serviceInfo);
33        if (serviceInfo != nullptr) {
34            free(serviceInfo);
35            result = true;
36        };
37
38        ServiceCtrlInfo *powerctrl = nullptr;
39        GetServiceCtrlInfo("ohos.startup.powerctrl", "reboot,updater", &powerctrl);
40        if (powerctrl != nullptr) {
41            free(powerctrl);
42            result = true;
43        };
44
45        ServiceCtrlInfo *ctrlInfo = nullptr;
46        std::string str(reinterpret_cast<const char*>(data), size);
47        GetServiceCtrlInfo(str.c_str(), "test", &ctrlInfo);
48        if (ctrlInfo != nullptr) {
49            free(ctrlInfo);
50            result = true;
51        };
52
53        return result;
54    }
55}
56
57/* Fuzzer entry point */
58extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
59{
60    /* Run your code on data */
61    OHOS::FuzzGetServiceCtrlInfo(data, size);
62    return 0;
63}