• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "medialibrary_extension_insert_fuzzer.h"
16 
17 #include <cstdint>
18 #include <string>
19 #include <fuzzer/FuzzedDataProvider.h>
20 
21 #include "data_ability_observer_interface.h"
22 #include "datashare_business_error.h"
23 #include "datashare_helper.h"
24 #include "datashare_predicates.h"
25 #include "datashare_values_bucket.h"
26 #include "media_datashare_ext_ability.h"
27 #include "media_datashare_stub_impl.h"
28 #include "media_log.h"
29 #include "runtime.h"
30 
31 namespace OHOS {
32 using namespace std;
33 using namespace AbilityRuntime;
34 using namespace DataShare;
35 static const int32_t NUM_BYTES = 1;
36 FuzzedDataProvider *provider = nullptr;
FuzzUri()37 static inline Uri FuzzUri()
38 {
39     return Uri(provider->ConsumeBytesAsString(NUM_BYTES));
40 }
41 
FuzzDataShareValuesBucket()42 static inline DataShareValuesBucket FuzzDataShareValuesBucket()
43 {
44     return {};
45 }
46 
InsertFuzzer(MediaDataShareExtAbility & extension)47 static inline void InsertFuzzer(MediaDataShareExtAbility &extension)
48 {
49     DataSharePredicates predicates;
50     DataShareValuesBucket values;
51     extension.Insert(FuzzUri(), FuzzDataShareValuesBucket());
52 }
53 
Init()54 static inline MediaDataShareExtAbility Init()
55 {
56     const std::unique_ptr<AbilityRuntime::Runtime> runtime;
57     return {(*runtime)};
58 }
59 } // namespace OHOS
60 
61 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)62 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
63 {
64     /* Run your code on data */
65     FuzzedDataProvider fdp(data, size);
66     OHOS::provider = &fdp;
67     if (data == nullptr) {
68         return 0;
69     }
70     auto extension = OHOS::Init();
71     OHOS::InsertFuzzer(extension);
72     return 0;
73 }