1 /*
2 * Copyright (c) 2021-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 "common.h"
17 #include "camera_device_impl.h"
18
19 namespace OHOS {
CameraDeviceFuzzTest(const uint8_t * rawData,size_t size)20 bool CameraDeviceFuzzTest(const uint8_t *rawData, size_t size)
21 {
22 if (rawData == nullptr) {
23 return false;
24 }
25 constexpr uint32_t sleepTime = 2;
26 uint32_t code = U32_AT(rawData);
27 rawData = rawData + OFFSET;
28 size = size - OFFSET;
29
30 MessageParcel data;
31 data.WriteInterfaceToken(ICameraDevice::GetDescriptor());
32 data.WriteBuffer(rawData, size);
33 data.RewindRead(0);
34 MessageParcel reply;
35 MessageOption option;
36
37 sptr<ICameraDevice> cameraDevice = new OHOS::Camera::CameraDeviceImpl();
38 sptr<CameraDeviceStub> IpcDevice = new CameraDeviceStub(cameraDevice);
39
40 sleep(sleepTime); // sleep two second
41 IpcDevice->OnRemoteRequest(code, data, reply, option);
42
43 return true;
44 }
45
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)46 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
47 {
48 if (size < OHOS::THRESHOLD) {
49 return 0;
50 }
51
52 OHOS::CameraDeviceFuzzTest(data, size);
53 return 0;
54 }
55 }
56