• 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 "admin_manager_fuzzer.h"
17 
18 #include "edm_ipc_interface_code.h"
19 #include "common_fuzzer.h"
20 #include "func_code.h"
21 
22 namespace OHOS {
23 namespace EDM {
24 constexpr size_t MIN_SIZE = 5;
25 constexpr uint32_t MIN_INTERAFCE_CODE = 1000;
26 
27 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)28 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
29 {
30     if (data == nullptr) {
31         return 0;
32     }
33     if (size < MIN_SIZE) {
34         return 0;
35     }
36     for (uint32_t code = EdmInterfaceCode::ADD_DEVICE_ADMIN; code <= EdmInterfaceCode::AUTHORIZE_ADMIN; code++) {
37         CommonFuzzer::OnRemoteRequestFuzzerTest(code, data, size);
38     }
39     uint32_t code = ((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]) % 3100;
40     if (code == EdmInterfaceCode::RESET_FACTORY || code == EdmInterfaceCode::SHUTDOWN ||
41         code == EdmInterfaceCode::REBOOT || code == EdmInterfaceCode::USB_READ_ONLY ||
42         code == EdmInterfaceCode::DISABLED_HDC || code == EdmInterfaceCode::DISABLE_USB ||
43         code < MIN_INTERAFCE_CODE) {
44         return 0;
45     }
46     uint32_t operateType = data[4] % 3;
47     code = POLICY_FUNC_CODE(operateType, code);
48     CommonFuzzer::OnRemoteRequestFuzzerTest(code, data, size);
49     return 0;
50 }
51 } // namespace EDM
52 } // namespace OHOS