1 /*
2  * Copyright (c) 2023-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 #define FUZZ_PROJECT_NAME "enterprise_device_mgr_stub_mock_fuzzer"
16 
17 #include "edm_ipc_interface_code.h"
18 #include "common_fuzzer.h"
19 #include "func_code.h"
20 #include "message_parcel.h"
21 
22 namespace OHOS {
23 namespace EDM {
24 constexpr size_t MIN_SIZE = 6;
25 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)26 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
27 {
28     if (data == nullptr) {
29         return 0;
30     }
31     if (size < MIN_SIZE) {
32         return 0;
33     }
34 
35     uint32_t code = (CommonFuzzer::GetU32Data(data)) % 3100;
36     if (code == EdmInterfaceCode::RESET_FACTORY || code == EdmInterfaceCode::SHUTDOWN ||
37         code == EdmInterfaceCode::REBOOT || code == EdmInterfaceCode::USB_READ_ONLY ||
38         code == EdmInterfaceCode::DISABLED_HDC || code == EdmInterfaceCode::DISABLE_USB) {
39         return 0;
40     }
41     uint32_t funcFlag = data[4] % 2;
42     uint32_t operateType = data[5] % 3;
43     code = CREATE_FUNC_CODE(funcFlag, operateType, code);
44 
45     MessageParcel parcel;
46     CommonFuzzer::SetParcelContent(parcel, data, size);
47     CommonFuzzer::OnRemoteRequestFuzzerTest(code, data, size, parcel);
48     return 0;
49 }
50 } // namespace EDM
51 } // namespace OHOS
52