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 "devauthservcancelbindrequest_fuzzer.h"
17 #include "device_auth.h"
18 #include "device_auth_defines.h"
19 #include "hc_dev_info.h"
20 #include "hc_log.h"
21 #include "json_utils.h"
22 #include "securec.h"
23 #include <unistd.h>
24 
25 namespace OHOS {
26     constexpr int64_t TEST_REQ_ID = 123;
27 
FuzzDoCancelBindRequest(const uint8_t * data,size_t size)28     bool FuzzDoCancelBindRequest(const uint8_t *data, size_t size)
29     {
30         if (data == nullptr) {
31             return false;
32         }
33         if (InitDeviceAuthService() != HC_SUCCESS) {
34             return false;
35         }
36         const DeviceGroupManager *gmInstance = GetGmInstance();
37         if (gmInstance == nullptr) {
38             DestroyDeviceAuthService();
39             return false;
40         }
41         std::string appId(reinterpret_cast<const char *>(data), size);
42         gmInstance->cancelRequest(TEST_REQ_ID, appId.c_str());
43         DestroyDeviceAuthService();
44         return true;
45     }
46 }
47 
48 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)49 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
50 {
51     /* Run your code on data */
52     OHOS::FuzzDoCancelBindRequest(data, size);
53     return 0;
54 }