• 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 "wappushbuffer_fuzzer.h"
17 
18 #define private public
19 
20 #include "addsmstoken_fuzzer.h"
21 #include "sms_wap_push_handler.h"
22 
23 using namespace OHOS::Telephony;
24 namespace OHOS {
25 static int32_t SIM_COUNT = 2;
26 
WapPushBuffer(const uint8_t * data,size_t size)27 void WapPushBuffer(const uint8_t *data, size_t size)
28 {
29     int32_t slotId = static_cast<int32_t>(size % SIM_COUNT);
30     std::string strValue(reinterpret_cast<const char *>(data), size);
31     std::unique_ptr<SmsWapPushHandler> smsWapPushHandler = std::make_unique<SmsWapPushHandler>(slotId);
32     smsWapPushHandler->DecodeWapPushPdu(strValue);
33 
34     auto decodeBuffer = std::make_shared<SmsWapPushBuffer>();
35     if (decodeBuffer == nullptr) {
36         return;
37     }
38     uint32_t desLen = static_cast<uint32_t>(size);
39     decodeBuffer->ReadDataBuffer(desLen);
40 
41     std::unique_ptr<char[]> inBuff = std::make_unique<char[]>(desLen);
42     decodeBuffer->WriteDataBuffer(std::move(inBuff), desLen);
43     decodeBuffer->GetCurPosition();
44     decodeBuffer->GetSize();
45 
46     uint8_t uint8tValue;
47     decodeBuffer->PeekOneByte(uint8tValue);
48     decodeBuffer->IncreasePointer(desLen);
49     decodeBuffer->DecreasePointer(desLen);
50     decodeBuffer->DecodeUintvar(desLen, desLen);
51 
52     decodeBuffer->DecodeShortLength(uint8tValue);
53     decodeBuffer->DecodeValueLength(desLen);
54     decodeBuffer->CharIsToken(uint8tValue);
55     decodeBuffer->DecodeTokenText(strValue, desLen);
56     decodeBuffer->DecodeText(strValue, desLen);
57 
58     decodeBuffer->DecodeQuotedText(strValue, desLen);
59     decodeBuffer->DecodeShortInteger(uint8tValue);
60 
61     uint64_t uint64tValue;
62     decodeBuffer->DecodeLongInteger(uint64tValue);
63     decodeBuffer->DecodeInteger(uint64tValue);
64 
65     decodeBuffer->DecodeIsShortInt();
66     decodeBuffer->DecodeIsString();
67     decodeBuffer->DecodeIsValueLength();
68     decodeBuffer->DecodeExtensionMedia();
69     decodeBuffer->DecodeConstrainedEncoding();
70 
71     bool isNoValue = slotId == 0 ? true : false;
72     decodeBuffer->DecodeTextValue(strValue, isNoValue);
73     decodeBuffer->DecodeNoValue(isNoValue);
74     decodeBuffer->MarkPosition();
75     decodeBuffer->UnMarkPosition();
76 }
77 
DoWapPushBufferWithMyAPI(const uint8_t * data,size_t size)78 void DoWapPushBufferWithMyAPI(const uint8_t *data, size_t size)
79 {
80     if (data == nullptr || size == 0) {
81         return;
82     }
83 
84     WapPushBuffer(data, size);
85 }
86 } // namespace OHOS
87 
88 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)89 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
90 {
91     /* Run your code on data */
92     OHOS::AddSmsTokenFuzzer token;
93     OHOS::DoWapPushBufferWithMyAPI(data, size);
94     return 0;
95 }
96