1 /*
2 * Copyright (c) 2022-2025 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 "dcameraenabledcameradevice_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20
21 #include "dcamera_provider.h"
22 #include "v1_1/id_camera_provider_callback.h"
23
24 namespace OHOS {
25 namespace DistributedHardware {
26 constexpr const char* TEST_ABILITY = R"({"SinkAbility": "SinkAbilityTest",
27 "SourceCodec": "SourceCodecTest"
28 })";
29
DcameraEnableDCameraDeviceFuzzTest(const uint8_t * data,size_t size)30 void DcameraEnableDCameraDeviceFuzzTest(const uint8_t* data, size_t size)
31 {
32 if ((data == nullptr) || (size == 0)) {
33 return;
34 }
35 std::string deviceId = "1";
36 std::string dhId = "2";
37 std::string abilityInfo(reinterpret_cast<const char*>(data), size);
38 DHBase dhBase;
39 dhBase.deviceId_ = deviceId;
40 dhBase.dhId_ = dhId;
41
42 sptr<IDCameraProviderCallback> callback;
43
44 DCameraProvider::GetInstance()->EnableDCameraDevice(dhBase, abilityInfo, callback);
45 dhBase.deviceId_ = "";
46 std::string emptyAbilityInfo = "";
47 DCameraProvider::GetInstance()->EnableDCameraDevice(dhBase, emptyAbilityInfo, callback);
48 std::string sinkAbilityInfo = "";
49 std::string sourceCodecInfo = "";
50 DCameraProvider::GetInstance()->GetAbilityInfo(abilityInfo, sinkAbilityInfo, sourceCodecInfo);
51 DCameraProvider::GetInstance()->GetAbilityInfo(TEST_ABILITY, sinkAbilityInfo, sourceCodecInfo);
52 }
53 }
54 }
55
56 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59 /* Run your code on data */
60 OHOS::DistributedHardware::DcameraEnableDCameraDeviceFuzzTest(data, size);
61 return 0;
62 }
63
64