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 "softbusadapterhisysevent_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <securec.h>
21 #include "softbus_error_code.h"
22 #include "softbus_adapter_hisysevent.h"
23 #include "softbus_hisysevt_connreporter.h"
24
25 namespace OHOS {
CreateOpenSessionCntMsg(SoftBusEvtReportMsg * msg)26 static void CreateOpenSessionCntMsg(SoftBusEvtReportMsg* msg)
27 {
28 (void)strcpy_s(msg->evtName, SOFTBUS_HISYSEVT_NAME_LEN, "TRANS_OPEN_SESSION_CNT");
29 msg->evtType = SOFTBUS_EVT_TYPE_STATISTIC;
30 msg->paramNum = SOFTBUS_EVT_PARAM_ONE;
31
32 SoftBusEvtParam* param = &msg->paramArray[SOFTBUS_EVT_PARAM_ZERO];
33 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, "SUCCESS_CNT");
34 param->paramType = SOFTBUS_EVT_PARAMTYPE_UINT32;
35 param->paramValue.u32v = 0;
36 }
37
SoftBusAdapterHiSysEventFuzzTest(const uint8_t * data,size_t size)38 void SoftBusAdapterHiSysEventFuzzTest(const uint8_t* data, size_t size)
39 {
40 int32_t tmpParam = *(reinterpret_cast<const int32_t *>(data));
41 SoftBusEvtReportMsg* msg = SoftbusCreateEvtReportMsg(tmpParam);
42 if (msg == nullptr) {
43 return;
44 }
45 CreateOpenSessionCntMsg(msg);
46 SoftbusWriteHisEvt(msg);
47 SoftbusFreeEvtReporMsg(msg);
48 }
49 } // namespace OHOS
50
51 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)52 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
53 {
54 if (data == nullptr || size < sizeof(int32_t)) {
55 return 0;
56 }
57
58 OHOS::SoftBusAdapterHiSysEventFuzzTest(data, size);
59
60 return 0;
61 }