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 "pdpcontextlistupdated_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20
21 #include "hril_data.h"
22 #include "hril_manager.h"
23 #include "hril_notification.h"
24 #include "system_ability_definition.h"
25
26 using namespace OHOS::Telephony;
27 namespace OHOS {
28 constexpr int32_t SLOT_NUM = 2;
29 constexpr int32_t REASON_TYPE = 2;
30 constexpr int32_t RETRY_TIME = 2;
31 constexpr int32_t ACTIVE_NUM = 2;
32 constexpr const char *NUMBER = "123";
33
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)34 void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
35 {
36 if (data == nullptr || size == 0) {
37 return;
38 }
39
40 int32_t slotId = static_cast<int32_t>(size % SLOT_NUM);
41 HRilErrNumber error = static_cast<HRilErrNumber>(size);
42
43 HRilDataCallResponse response;
44 response.reason = static_cast<int32_t>(size) % REASON_TYPE;
45 response.retryTime = static_cast<int32_t>(size) % RETRY_TIME;
46 response.cid = static_cast<int32_t>(size);
47 response.active = static_cast<int32_t>(size) % ACTIVE_NUM;
48 response.type = const_cast<char *>(NUMBER);
49 response.netPortName = const_cast<char *>(NUMBER);
50 response.address = const_cast<char *>(NUMBER);
51 response.dns = const_cast<char *>(NUMBER);
52 response.dnsSec = const_cast<char *>(NUMBER);
53 response.gateway = const_cast<char *>(NUMBER);
54 response.maxTransferUnit = static_cast<int32_t>(size);
55 response.pCscfPrimAddr = const_cast<char *>(NUMBER);
56 response.pCscfSecAddr = const_cast<char *>(NUMBER);
57 response.pduSessionId = static_cast<int32_t>(size);
58
59 HRilManager hrilManager;
60 std::shared_ptr<HRilData> hrilData = std::make_shared<HRilData>(slotId, hrilManager);
61 hrilData->PdpContextListUpdated(HRIL_RESPONSE_NOTICE, error, &response, sizeof(HRilDataCallResponse));
62 return;
63 }
64 } // namespace OHOS
65
66 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)67 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
68 {
69 /* Run your code on data */
70 OHOS::DoSomethingInterestingWithMyAPI(data, size);
71 return 0;
72 }
73