• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "hcamera_host_manager_fuzzer.h"
17 
18 #include "camera_log.h"
19 #include "message_parcel.h"
20 #include "token_setproc.h"
21 #include "nativetoken_kit.h"
22 #include "securec.h"
23 #include "os_account_manager.h"
24 #include "output/sketch_wrapper.h"
25 #include "hcamera_service.h"
26 #include "ipc_skeleton.h"
27 
28 using namespace OHOS::CameraStandard::DeferredProcessing;
29 namespace OHOS {
30 namespace CameraStandard {
31 using OHOS::HDI::Camera::V1_0::ICameraDeviceCallback;
32 static constexpr int32_t MIN_SIZE_NUM = 128;
33 const size_t MAX_LENGTH_STRING = 64;
34 
35 std::shared_ptr<HCameraHostManager> HCameraHostManagerFuzzer::fuzz_{nullptr};
36 std::shared_ptr<HCameraHostManager::CameraHostInfo> HCameraHostManagerFuzzer::hostInfo{nullptr};
37 
HCameraHostManagerFuzzTest1(FuzzedDataProvider & fdp)38 void HCameraHostManagerFuzzer::HCameraHostManagerFuzzTest1(FuzzedDataProvider& fdp)
39 {
40     if (fdp.remaining_bytes() < MIN_SIZE_NUM) {
41         return;
42     }
43     std::shared_ptr<HCameraHostManager::StatusCallback> statusCallback = std::make_shared<StatusCallbackDemo>();
44     fuzz_ = std::make_shared<HCameraHostManager>(statusCallback);
45     CHECK_RETURN_ELOG(!fuzz_, "Create fuzz_ Error");
46     std::string cameraId(fdp.ConsumeRandomLengthString(MAX_LENGTH_STRING));
47     bool isEnable = fdp.ConsumeBool();
48     std::shared_ptr<OHOS::Camera::CameraMetadata> ability;
49     fuzz_->GetCameraAbility(cameraId, ability);
50     fuzz_->SetFlashlight(cameraId, isEnable);
51 }
52 
Test(uint8_t * data,size_t size)53 void Test(uint8_t* data, size_t size)
54 {
55     FuzzedDataProvider fdp(data, size);
56     auto hCameraHostManagerFuzzer = std::make_unique<HCameraHostManagerFuzzer>();
57     if (hCameraHostManagerFuzzer == nullptr) {
58         MEDIA_INFO_LOG("hCameraHostManagerFuzzer is null");
59         return;
60     }
61     hCameraHostManagerFuzzer->HCameraHostManagerFuzzTest1(fdp);
62 }
63 
64 } // namespace CameraStandard
65 } // namespace OHOS
66 
67 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)68 extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size)
69 {
70     OHOS::CameraStandard::Test(data, size);
71     return 0;
72 }