• 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 "reminder_request_timer.h"
17 #include "reminder_datashare_helper.h"
18 #include "reminder_calendar_share_table.h"
19 #include "reminderdatasharehelper_fuzzer.h"
20 #include <fuzzer/FuzzedDataProvider.h>
21 
22 namespace OHOS {
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)23     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp)
24     {
25         int32_t id = fdp->ConsumeIntegral<int32_t>();
26         std::string bundleName = fdp->ConsumeRandomLengthString();
27         constexpr uint64_t seconds = 1200;
28         sptr<Notification::ReminderRequest> reminder = new Notification::ReminderRequestTimer(seconds);
29 
30         Notification::ReminderDataShareHelper& helper = Notification::ReminderDataShareHelper::GetInstance();
31         helper.RegisterObserver();
32         helper.UnRegisterObserver();
33         std::map<std::string, sptr<Notification::ReminderRequest>> reminders;
34         helper.Query(reminders);
35         helper.Update(id, id);
36         helper.StartDataExtension(id);
37         helper.SetUserId(id);
38         helper.UpdateCalendarUid();
39         helper.GetCacheReminders();
40         helper.InsertCacheReminders(reminders);
41         helper.OnDataInsertOrDelete();
42         DataShare::DataShareObserver::ChangeInfo info;
43         helper.OnDataUpdate(info);
44         auto result = helper.CreateDataShareHelper(Notification::ReminderCalendarShareTable::PROXY);
45         helper.ReleaseDataShareHelper(result);
46         helper.GetColumns();
47         helper.CreateReminder(info);
48         helper.InitNormalInfo(reminder);
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     FuzzedDataProvider fdp(data, size);
58     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
59     return 0;
60 }
61