• 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 "streammsgmanager_fuzzer.h"
17 #include "stream_msg_manager.h"
18 #include "common_inner.h"
19 #include <cstddef>
20 #include <cstdint>
21 
22 using namespace std;
23 
24 namespace OHOS {
SendTest(const uint8_t * data,size_t size)25     void SendTest(const uint8_t* data, size_t size)
26     {
27         if (data == nullptr || size < sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int)) {
28             return;
29         }
30         uint32_t offset = 0;
31         Communication::SoftBus::HistoryStats stats;
32         stats.periodFrameNum = *(reinterpret_cast<const int *>(data));
33         offset += sizeof(int);
34         stats.avgFrameInterval = *(reinterpret_cast<const int *>(data + offset));
35         offset += sizeof(int);
36         stats.minFrameInterval = *(reinterpret_cast<const int *>(data + offset));
37         offset += sizeof(int);
38         stats.maxFrameInterval = *(reinterpret_cast<const int *>(data + offset));
39 
40         Communication::SoftBus::StreamMsgManager streamMsgManager;
41         streamMsgManager.Send((const Communication::SoftBus::HistoryStats &)stats);
42     }
43 
RecvTest(const uint8_t * data,size_t size)44     void RecvTest(const uint8_t* data, size_t size)
45     {
46         if (data == nullptr || size < sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int)) {
47             return;
48         }
49         uint32_t offset = 0;
50         Communication::SoftBus::HistoryStats stats;
51         stats.periodFrameNum = *(reinterpret_cast<const int *>(data));
52         offset += sizeof(int);
53         stats.avgFrameInterval = *(reinterpret_cast<const int *>(data + offset));
54         offset += sizeof(int);
55         stats.minFrameInterval = *(reinterpret_cast<const int *>(data + offset));
56         offset += sizeof(int);
57         stats.maxFrameInterval = *(reinterpret_cast<const int *>(data + offset));
58 
59         Communication::SoftBus::StreamMsgManager streamMsgManager;
60         streamMsgManager.Recv((const Communication::SoftBus::HistoryStats &)stats);
61     }
62 
UpdateTest(const uint8_t * data,size_t size)63     void UpdateTest(const uint8_t* data, size_t size)
64     {
65         if (data == nullptr || size < sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int)) {
66             return;
67         }
68         uint32_t offset = 0;
69         Communication::SoftBus::HistoryStats stats;
70         stats.periodFrameNum = *(reinterpret_cast<const int *>(data));
71         offset += sizeof(int);
72         stats.avgFrameInterval = *(reinterpret_cast<const int *>(data + offset));
73         offset += sizeof(int);
74         stats.minFrameInterval = *(reinterpret_cast<const int *>(data + offset));
75         offset += sizeof(int);
76         stats.maxFrameInterval = *(reinterpret_cast<const int *>(data + offset));
77 
78         Communication::SoftBus::StreamMsgManager streamMsgManager;
79         streamMsgManager.Update((const Communication::SoftBus::HistoryStats &)stats);
80     }
81 
82 } // namespace OHOS
83 
84 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)85 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
86 {
87     /* Run your code on data */
88     OHOS::SendTest(data, size);
89     OHOS::RecvTest(data, size);
90     OHOS::UpdateTest(data, size);
91     return 0;
92 }
93