blob: 173c76547ec644b9c61cc65bf9cb6c19f883ffdd [file] [log] [blame]
Pawanbe708612022-08-19 17:51:44 +00001/*
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
Pawan Wagh25effc32023-03-15 20:50:36 +000017#include <android-base/logging.h>
Pawanbe708612022-08-19 17:51:44 +000018#include <fuzzbinder/libbinder_driver.h>
19
Weston Carvalho6ab20652024-12-03 15:21:45 -060020#include "VendorVoldNativeService.h"
Pawanbe708612022-08-19 17:51:44 +000021#include "VoldNativeService.h"
Pawan Wagh25effc32023-03-15 20:50:36 +000022#include "sehandle.h"
Pawanbe708612022-08-19 17:51:44 +000023
24using ::android::fuzzService;
25using ::android::sp;
26
27struct selabel_handle* sehandle;
28
Pawan Wagh25effc32023-03-15 20:50:36 +000029extern "C" int LLVMFuzzerInitialize(int argc, char argv) {
30 sehandle = selinux_android_file_context_handle();
31 if (!sehandle) {
32 LOG(ERROR) << "Failed to get SELinux file contexts handle in voldFuzzer!";
33 exit(1);
34 }
35 selinux_android_set_sehandle(sehandle);
36 return 0;
37}
38
Pawanbe708612022-08-19 17:51:44 +000039extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
Akhilesh Sanikop45fee082025-01-31 15:55:05 +053040 // TODO(b/183141167): need to rewrite 'dump' to avoid SIGPIPE.
41 signal(SIGPIPE, SIG_IGN);
Pawanbe708612022-08-19 17:51:44 +000042 auto voldService = sp<android::vold::VoldNativeService>::make();
Weston Carvalho6ab20652024-12-03 15:21:45 -060043 auto voldVendorService = sp<android::vold::VendorVoldNativeService>::make();
44 fuzzService({voldService, voldVendorService}, FuzzedDataProvider(data, size));
Pawanbe708612022-08-19 17:51:44 +000045 return 0;
46}