• 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 "notifyChange_fuzzer.h"
16 #include <fcntl.h>
17 #include <vector>
18 #include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h"
19 #include "datashare_helper.h"
20 #include "file_access_extension_info.h"
21 #include "file_access_framework_errno.h"
22 #include "file_access_helper.h"
23 #include "file_filter.h"
24 #include "iservice_registry.h"
25 #include "medialibrary_errno.h"
26 #include "media_library_manager.h"
27 #include "media_log.h"
28 #include "result_set_utils.h"
29 #include "scanner_utils.h"
30 
31 using namespace OHOS;
32 using namespace OHOS::FileAccessFwk;
33 namespace OHOS {
34 namespace MediaLibrary {
NotifyChangeFuzzTest(const uint8_t * data,size_t size)35 bool NotifyChangeFuzzTest(const uint8_t *data, size_t size)
36 {
37     if ((data == nullptr) || (size <= 0)) {
38         return false;
39     }
40 
41     Uri notifyChangeUri(std::string(reinterpret_cast<const char*>(data), size));
42     DataShare::DataSharePredicates predicates;
43     std::string selections = std::string(reinterpret_cast<const char*>(data), size);
44     predicates.SetWhereClause(selections);
45 
46     auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
47     if (saManager == nullptr) {
48         return false;
49     }
50     auto remoteObj = saManager->GetSystemAbility(5003);
51     if (remoteObj == nullptr) {
52         return false;
53     }
54     auto helper = DataShare::DataShareHelper::Creator(remoteObj, MEDIALIBRARY_DATA_URI);
55     if (helper == nullptr) {
56         return false;
57     }
58     helper->NotifyChange(notifyChangeUri);
59     return true;
60 }
61 } // namespace StorageManager
62 } // namespace OHOS
63 
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
66 {
67     /* Run your code on data */
68     OHOS::MediaLibrary::NotifyChangeFuzzTest(data, size);
69     return 0;
70 }