xref: /aosp_15_r20/frameworks/native/cmds/installd/tests/fuzzers/InstalldServiceFuzzer.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <fuzzbinder/libbinder_driver.h>
17 
18 #include "InstalldNativeService.h"
19 #include "dexopt.h"
20 
21 using ::android::fuzzService;
22 using ::android::sp;
23 using ::android::installd::InstalldNativeService;
24 
25 namespace android {
26 namespace installd {
27 
calculate_oat_file_path(char path[PKG_PATH_MAX],const char * oat_dir,const char * apk_path,const char * instruction_set)28 bool calculate_oat_file_path(char path[PKG_PATH_MAX], const char* oat_dir, const char* apk_path,
29                              const char* instruction_set) {
30     return calculate_oat_file_path_default(path, oat_dir, apk_path, instruction_set);
31 }
32 
calculate_odex_file_path(char path[PKG_PATH_MAX],const char * apk_path,const char * instruction_set)33 bool calculate_odex_file_path(char path[PKG_PATH_MAX], const char* apk_path,
34                               const char* instruction_set) {
35     return calculate_odex_file_path_default(path, apk_path, instruction_set);
36 }
37 
create_cache_path(char path[PKG_PATH_MAX],const char * src,const char * instruction_set)38 bool create_cache_path(char path[PKG_PATH_MAX], const char* src, const char* instruction_set) {
39     return create_cache_path_default(path, src, instruction_set);
40 }
41 
force_compile_without_image()42 bool force_compile_without_image() {
43     return false;
44 }
45 
46 } // namespace installd
47 } // namespace android
48 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)49 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
50     // TODO(b/183141167): need to rewrite 'dump' to avoid SIGPIPE.
51     signal(SIGPIPE, SIG_IGN);
52     auto service = sp<InstalldNativeService>::make();
53     fuzzService(service, FuzzedDataProvider(data, size));
54     return 0;
55 }