• 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 <cstddef>
17 #include <cstdint>
18 #include <string>
19 #include <vector>
20 #include "locale_config.h"
21 #include "localeconfigget_fuzzer.h"
22 
23 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)24     bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
25     {
26         using namespace Global::I18n;
27         LocaleConfig::GetSystemLanguage();
28         LocaleConfig::GetSystemRegion();
29         LocaleConfig::GetSystemLocale();
30         std::vector<std::string> ret;
31         LocaleConfig::GetSystemLanguages(ret);
32         LocaleConfig::GetSystemCountries(ret);
33 
34         std::string input(reinterpret_cast<const char*>(data), size);
35         LocaleConfig::IsSuggested(input);
36         const size_t minimalLocaleLength = 2;
37         if (input.length() > minimalLocaleLength) {
38             std::string firstInput(input, 0, minimalLocaleLength);
39             std::string secondInput(input, minimalLocaleLength);
40             LocaleConfig::IsSuggested(firstInput, secondInput);
41             LocaleConfig::GetDisplayLanguage(firstInput, secondInput, true);
42             LocaleConfig::GetDisplayLanguage(firstInput, secondInput, false);
43             LocaleConfig::GetDisplayRegion(firstInput, secondInput, true);
44             LocaleConfig::GetDisplayRegion(firstInput, secondInput, false);
45         }
46         LocaleConfig::IsRTL(input);
47         LocaleConfig::GetValidLocale(input);
48 
49         return true;
50     }
51 }
52 
53 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)54 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
55 {
56     /* Run your code on data */
57     OHOS::DoSomethingInterestingWithMyAPI(data, size);
58     return 0;
59 }
60 
61