• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "processauthdata_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 
FuzzDoProcessData(const uint8_t * data,size_t size)35     bool FuzzDoProcessData(const uint8_t* data, size_t size)
36     {
37         const GroupAuthManager *gaInstance = GetGaInstance();
38         if (gaInstance == nullptr) {
39             return false;
40         }
41         if (data == nullptr) {
42             return false;
43         }
44         if (size < sizeof(int64_t)) {
45             return false;
46         }
47         const int64_t *authReqId = reinterpret_cast<const int64_t *>(data);
48         DeviceAuthCallback gaCallback;
49         gaCallback.onError = OnError;
50         gaCallback.onFinish = OnFinish;
51         gaCallback.onSessionKeyReturned = OnSessionKeyReturned;
52         gaCallback.onTransmit = onTransmit;
53         gaCallback.onRequest = onRequest;
54         gaInstance->processData(*authReqId, data, (uint32_t)size, &gaCallback);
55         return true;
56     }
57 }
58 
59 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
61 {
62     /* Run your code on data */
63     OHOS::FuzzDoProcessData(data, size);
64     return 0;
65 }
66 
67