1 /*
2  * Copyright (c) 2024 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 "system_properties_adapter_impl_fuzzer.h"
17 
18 #include <cstdlib>
19 #include <cstring>
20 #include <string>
21 
22 #include "system_properties_adapter_impl.h"
23 
24 namespace OHOS {
25 
SystemPropertiesAdapterFuzzTest(const uint8_t * data,size_t size)26 bool SystemPropertiesAdapterFuzzTest(const uint8_t* data, size_t size)
27 {
28     size_t keySize = std::min(size, static_cast<size_t>(32));
29     std::string key(reinterpret_cast<const char*>(data), keySize);
30 
31     size_t valueSize = size > keySize ? size - keySize : 0;
32     std::string value(reinterpret_cast<const char*>(data + keySize), valueSize);
33 
34     bool boolResult = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetBoolParameter(key, false);
35     std::string productModel = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetDeviceInfoProductModel();
36     std::string brand = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetDeviceInfoBrand();
37     int32_t majorVersion = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetSoftwareMajorVersion();
38     int32_t seniorVersion = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetSoftwareSeniorVersion();
39 
40     (void)boolResult;
41     (void)productModel;
42     (void)brand;
43     (void)majorVersion;
44     (void)seniorVersion;
45 
46     return true;
47 }
48 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)49 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
50 {
51     return OHOS::SystemPropertiesAdapterFuzzTest(data, size) ? 0 : 1;
52 }
53 
54 } // namespace OHOS