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 "startusingpermission001_fuzzer.h"
17
18 #include <iostream>
19 #include <thread>
20 #include <string>
21 #include <vector>
22 #undef private
23 #include "privacy_kit.h"
24
25 using namespace std;
26 using namespace OHOS::Security::AccessToken;
27
28 class CbCustomizeTest : public StateCustomizedCbk {
29 public:
CbCustomizeTest()30 explicit CbCustomizeTest() : StateCustomizedCbk()
31 {
32 }
33
~CbCustomizeTest()34 ~CbCustomizeTest()
35 {}
36
StateChangeNotify(AccessTokenID tokenId,bool isShowing)37 virtual void StateChangeNotify(AccessTokenID tokenId, bool isShowing)
38 {
39 isShowing_ = true;
40 }
41
42 bool isShowing_ = false;
43 };
44
45 namespace OHOS {
StartUsingPermission001FuzzTest(const uint8_t * data,size_t size)46 bool StartUsingPermission001FuzzTest(const uint8_t* data, size_t size)
47 {
48 if ((data == nullptr) || (size == 0)) {
49 return false;
50 }
51
52 AccessTokenID tokenId = static_cast<AccessTokenID>(size);
53 std::string testName(reinterpret_cast<const char*>(data), size);
54 auto callback = std::make_shared<CbCustomizeTest>();
55
56 int32_t result = PrivacyKit::StartUsingPermission(tokenId, testName, callback);
57
58 return result == RET_SUCCESS;
59 }
60 }
61
62 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)63 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
64 {
65 /* Run your code on data */
66 OHOS::StartUsingPermission001FuzzTest(data, size);
67 return 0;
68 }
69