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
16 #include "camera_timer_fuzzer.h"
17 #include "camera_timer.h"
18 #include "hstream_capture.h"
19 #include "message_parcel.h"
20 #include "nativetoken_kit.h"
21 #include "token_setproc.h"
22 #include "accesstoken_kit.h"
23 #include "camera_metadata_info.h"
24 #include "metadata_utils.h"
25 #include "test_token.h"
26
27 namespace {
28
29 const int32_t LIMITSIZE = 5;
30
31 }
32
33 namespace OHOS {
34 namespace CameraStandard {
35
36 std::shared_ptr<CameraTimer> CameraTimerFuzzer::fuzz_{nullptr};
37
Test(uint8_t * rawData,size_t size)38 void CameraTimerFuzzer::Test(uint8_t *rawData, size_t size)
39 {
40 if (rawData == nullptr || size < LIMITSIZE) {
41 return;
42 }
43 CHECK_RETURN_ELOG(!TestToken().GetAllCameraPermission(), "GetPermission error");
44
45 fuzz_ = CameraTimer::GetInstance();
46 CHECK_RETURN_ELOG(!fuzz_, "Create fuzz_ Error");
47 MessageParcel data;
48 data.WriteRawData(rawData, size);
49
50 data.RewindRead(0);
51
52 fuzz_->IncreaseUserCount();
53 fuzz_->DecreaseUserCount();
54
55 TimerCallback callback = [] {
56 // do nothing
57 };
58
59 data.RewindRead(0);
60 uint32_t interval = data.ReadUint32();
61
62 data.RewindRead(0);
63 bool once = data.ReadBool();
64
65 uint32_t timerId = fuzz_->Register(callback, interval, once);
66
67 fuzz_->Unregister(timerId);
68 }
69
70 } // namespace CameraStandard
71 } // namespace OHOS
72
73 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)74 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
75 {
76 /* Run your code on data */
77 OHOS::CameraStandard::CameraTimerFuzzer::Test(data, size);
78 return 0;
79 }