• 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 "isvalidnumberstring_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #define private public
22 #include "addcoreservicetoken_fuzzer.h"
23 #include "napi_util.h"
24 #include "sim_char_decode.h"
25 #include "sim_number_decode.h"
26 #include "system_ability_definition.h"
27 
28 using namespace OHOS::Telephony;
29 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)30 void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
31 {
32     if (data == nullptr || size == 0) {
33         return;
34     }
35 
36     auto simCharDecode = std::make_shared<SimCharDecode>();
37     auto simNumberDecode = std::make_shared<SimNumberDecode>();
38     int32_t bcdExtType = static_cast<int32_t>(size);
39     uint8_t result = static_cast<uint8_t>(size);
40     char argument = static_cast<char>(size);
41     std::string str(reinterpret_cast<const char *>(data), size);
42     std::string number(reinterpret_cast<const char *>(data), size);
43     std::vector<uint8_t> bcdCodes;
44     bcdCodes.push_back(result);
45     bool includeLen = static_cast<int32_t>(size % 2);
46     simCharDecode->IsChineseString(str);
47     simNumberDecode->IsValidNumberString(number);
48     simNumberDecode->CharToBCD(argument, result, bcdExtType);
49     simNumberDecode->NumberConvertToBCD(number, bcdCodes, includeLen, bcdExtType);
50     simNumberDecode->BcdToChar(result, argument, bcdExtType);
51 }
52 } // namespace OHOS
53 
54 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)55 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
56 {
57     OHOS::AddCoreServiceTokenFuzzer token;
58     /* Run your code on data */
59     OHOS::DoSomethingInterestingWithMyAPI(data, size);
60     return 0;
61 }
62