• 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 "sendstream_fuzzer.h"
17 
18 #include <cstddef>
19 
20 #include "securec.h"
21 #include "session.h"
22 #include "softbus_adapter_mem.h"
23 
24 namespace OHOS {
SendStreamTest(const uint8_t * data,size_t size)25 void SendStreamTest(const uint8_t* data, size_t size)
26 {
27     if (data == nullptr || size < sizeof(int64_t)) {
28         return;
29     }
30     uint8_t *ptr = static_cast<uint8_t *>(SoftBusCalloc(size + 1));
31     if (ptr == nullptr) {
32         return;
33     }
34     if (memcpy_s(ptr, size, data, size) != EOK) {
35         SoftBusFree(ptr);
36         return;
37     }
38     int32_t sessionId = *(reinterpret_cast<const int32_t *>(ptr));
39     StreamData streamdata = {
40         .buf = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
41         .bufLen = size,
42     };
43     StreamData ext = {
44         .buf = const_cast<char *>(reinterpret_cast<const char *>(ptr)),
45         .bufLen = size,
46     };
47     TV tv = {
48         .type = *(reinterpret_cast<const int32_t *>(ptr)),
49         .value = *(reinterpret_cast<const int64_t *>(ptr)),
50     };
51     StreamFrameInfo param = {
52         .frameType = *(reinterpret_cast<const int32_t *>(ptr)),
53         .timeStamp = *(reinterpret_cast<const int32_t *>(ptr)),
54         .seqNum = *(reinterpret_cast<const int32_t *>(ptr)),
55         .seqSubNum = *(reinterpret_cast<const int32_t *>(ptr)),
56         .level = *(reinterpret_cast<const int32_t *>(ptr)),
57         .bitMap = *(reinterpret_cast<const int32_t *>(ptr)),
58         .tvCount = 1,
59         .tvList = &tv,
60     };
61     SendStream(sessionId, &streamdata, &ext, &param);
62     SoftBusFree(ptr);
63 }
64 } // namespace OHOS
65 
66 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)67 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
68 {
69     /* Run your code on data */
70     OHOS::SendStreamTest(data, size);
71     return 0;
72 }
73