• 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 
16 #include "camera_restore_param_fuzzer.h"
17 #include "hcamera_restore_param.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 = 24;
30 
31 }
32 
33 namespace OHOS {
34 namespace CameraStandard {
35 
36 std::shared_ptr<HCameraRestoreParam> CameraRestoreParamFuzzer::fuzz_{nullptr};
37 
Test(uint8_t * data,size_t size)38 void CameraRestoreParamFuzzer::Test(uint8_t* data, size_t size)
39 {
40     if (fdp.remaining_bytes() < LIMITSIZE) {
41         return;
42     }
43     CHECK_RETURN_ELOG(!TestToken().GetAllCameraPermission(), "GetPermission error");
44 
45     std::string clientName;
46     std::string cameraId;
47     fuzz_ = std::make_shared<HCameraRestoreParam>(clientName, cameraId);
48     CHECK_RETURN_ELOG(!fuzz_, "Create fuzz_ Error");
49 
50     int32_t opMode = fdp.ConsumeIntegral<int32_t>();
51     fuzz_->SetCameraOpMode(opMode);
52 
53     int foldStaus = fdp.ConsumeIntegral<int32_t>();
54     fuzz_->SetFoldStatus(foldStaus);
55 
56     timeval closeCameraTime = {
57         fdp.ConsumeIntegral<uint32_t>(),
58         fdp.ConsumeIntegral<uint32_t>(),
59     };
60     fuzz_->SetCloseCameraTime(closeCameraTime);
61 
62     int activeTime = fdp.ConsumeIntegral<int32_t>();
63     fuzz_->SetStartActiveTime(activeTime);
64 
65     RestoreParamTypeOhos restoreParamType = RestoreParamTypeOhos::NO_NEED_RESTORE_PARAM_OHOS;
66     fuzz_->SetRestoreParamType(restoreParamType);
67 
68     std::shared_ptr<OHOS::Camera::CameraMetadata> settings;
69     fuzz_->SetSetting(settings);
70 
71     std::vector<StreamInfo_V1_1> streamInfos;
72     fuzz_->SetStreamInfo(streamInfos);
73 
74     auto obj = std::make_unique<int32_t>(fdp.ConsumeIntegral<int32_t>());
75     const void *objectId = obj.get();
76     fuzz_->IncStrongRef(objectId);
77     fuzz_->IncWeakRef(objectId);
78     fuzz_->AttemptIncStrong(objectId);
79     fuzz_->AttemptIncStrongRef(objectId);
80     fuzz_->DecStrongRef(objectId);
81     fuzz_->DecWeakRef(objectId);
82     fuzz_->AttemptAcquire(objectId);
83 }
84 
85 } // namespace CameraStandard
86 } // namespace OHOS
87 
88 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)89 extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size)
90 {
91     /* Run your code on data */
92     OHOS::CameraStandard::CameraRestoreParamFuzzer::Test(data, size);
93     return 0;
94 }