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 "registercallback_fuzzer.h"
17
18 namespace OHOS {
OnError(int64_t requestId,int operationCode,int errorCode,const char * errorReturn)19 void OnError(int64_t requestId, int operationCode, int errorCode, const char *errorReturn) {}
20
OnFinish(int64_t requestId,int operationCode,const char * authReturn)21 void OnFinish(int64_t requestId, int operationCode, const char *authReturn) {}
22
OnSessionKeyReturned(int64_t requestId,const uint8_t * sessionKey,uint32_t sessionKeyLen)23 void OnSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen) {}
24
onTransmit(int64_t requestId,const uint8_t * data,uint32_t dataLen)25 bool onTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen)
26 {
27 return true;
28 }
29
onRequest(int64_t requestId,int operationCode,const char * reqParam)30 char *onRequest(int64_t requestId, int operationCode, const char* reqParam)
31 {
32 return nullptr;
33 }
34
FuzzDoRegisterCallback(const uint8_t * data,size_t size)35 bool FuzzDoRegisterCallback(const uint8_t* data, size_t size)
36 {
37 const DeviceGroupManager *gmInstance = GetGmInstance();
38 if (gmInstance == nullptr) {
39 return false;
40 }
41 if (data == nullptr) {
42 return false;
43 }
44 std::string appId(reinterpret_cast<const char *>(data), size);
45 DeviceAuthCallback callback;
46 callback.onError = OnError;
47 callback.onFinish = OnFinish;
48 callback.onSessionKeyReturned = OnSessionKeyReturned;
49 callback.onTransmit = onTransmit;
50 callback.onRequest = onRequest;
51 gmInstance->regCallback(appId.c_str(), &callback);
52 return true;
53 }
54 }
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 /* Run your code on data */
60 OHOS::FuzzDoRegisterCallback(data, size);
61 return 0;
62 }
63
64