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 "unregistertokensynccallback_fuzzer.h"
17
18 #include "accesstoken_kit.h"
19 #include "token_setproc.h"
20 #include "token_sync_kit_interface.h"
21
22 using namespace std;
23 using namespace OHOS::Security::AccessToken;
24
25 namespace OHOS {
NativeTokenGet()26 bool NativeTokenGet()
27 {
28 AccessTokenID token = AccessTokenKit::GetNativeTokenId("token_sync_service");
29 if (token == 0) {
30 return false;
31 }
32 SetSelfTokenID(token);
33 return true;
34 }
RegisterTokenSyncCallbackFuzzTest(const uint8_t * data,size_t size)35 bool RegisterTokenSyncCallbackFuzzTest(const uint8_t* data, size_t size)
36 {
37 if ((data == nullptr) || (size == 0)) {
38 return false;
39 }
40 #ifdef TOKEN_SYNC_ENABLE
41 int32_t result = AccessTokenKit::UnRegisterTokenSyncCallback();
42 return result == RET_SUCCESS;
43 #else
44 return true;
45 #endif // TOKEN_SYNC_ENABLE
46 }
47 }
48
49 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)50 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
51 {
52 #ifdef TOKEN_SYNC_ENABLE
53 OHOS::NativeTokenGet();
54 #endif
55 /* Run your code on data */
56 OHOS::RegisterTokenSyncCallbackFuzzTest(data, size);
57 return 0;
58 }