• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "ohpredicates_fuzzer.h"
16 #include <fuzzer/FuzzedDataProvider.h>
17 #include "oh_predicates.h"
18 #include "relational_store.h"
19 #include <iostream>
20 
OhPredicatesFuzzTest(FuzzedDataProvider & provider)21 void OhPredicatesFuzzTest(FuzzedDataProvider &provider)
22 {
23     static bool runEndFlag = false;
24     std::string tableName = provider.ConsumeRandomLengthString();
25     std::string field = provider.ConsumeRandomLengthString();
26     std::string pattern = provider.ConsumeRandomLengthString();
27 
28     OH_Predicates *predicates = OH_Rdb_CreatePredicates(tableName.c_str());
29     OH_Predicates_NotLike(predicates, field.c_str(), pattern.c_str());
30     OH_Predicates_Glob(predicates, field.c_str(), pattern.c_str());
31     OH_Predicates_NotGlob(predicates, field.c_str(), pattern.c_str());
32 
33     if (!runEndFlag) {
34         runEndFlag = true;
35         std::cout << "OhPredicatesFuzzTest end" << std::endl;
36     }
37     if (predicates != nullptr) {
38         predicates->destroy(predicates);
39     }
40 }
41 
42 
43 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)44 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
45 {
46     /* Run your code on data */
47     FuzzedDataProvider provider(data, size);
48 
49     // Test OH_Predicates_NotLike, OH_Predicates_Glob, OH_Predicates_NotGlob
50     OhPredicatesFuzzTest(provider);
51     return 0;
52 }
53