Add fuzzer for bluetooth socket AIDL
Bug: 342012881
Test: m android.hardware.bluetooth.socket-service_fuzzer
Change-Id: I4324cb5d35ecf4d4bdbc79fd007ae515577ec998
diff --git a/bluetooth/socket/OWNERS b/bluetooth/socket/OWNERS
new file mode 100644
index 0000000..e7a60e6
--- /dev/null
+++ b/bluetooth/socket/OWNERS
@@ -0,0 +1,5 @@
+# Bug component: 27441
+
+include platform/packages/modules/Bluetooth:/OWNERS
+
+jaydenk@google.com
diff --git a/bluetooth/socket/aidl/default/Android.bp b/bluetooth/socket/aidl/default/Android.bp
index dd26f1f..10e673c 100644
--- a/bluetooth/socket/aidl/default/Android.bp
+++ b/bluetooth/socket/aidl/default/Android.bp
@@ -22,6 +22,25 @@
],
}
+cc_fuzz {
+ name: "android.hardware.bluetooth.socket-service_fuzzer",
+ team: "trendy_team_bluetooth",
+ defaults: ["service_fuzzer_defaults"],
+ srcs: [
+ "fuzzer.cpp",
+ "BluetoothSocket.cpp",
+ ],
+ static_libs: [
+ "android.hardware.bluetooth.socket-V1-ndk",
+ "liblog",
+ ],
+ fuzz_config: {
+ cc: [
+ "jaydenk@google.com",
+ ],
+ },
+}
+
filegroup {
name: "manifest_android.hardware.bluetooth.socket-service.default.xml",
srcs: ["bluetooth-socket-service-default.xml"],
diff --git a/bluetooth/socket/aidl/default/fuzzer.cpp b/bluetooth/socket/aidl/default/fuzzer.cpp
new file mode 100644
index 0000000..062db0f
--- /dev/null
+++ b/bluetooth/socket/aidl/default/fuzzer.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <fuzzbinder/libbinder_ndk_driver.h>
+#include <fuzzer/FuzzedDataProvider.h>
+
+#include "BluetoothSocket.h"
+
+using ::aidl::android::hardware::bluetooth::socket::impl::BluetoothSocket;
+using ::android::fuzzService;
+using ::ndk::SharedRefBase;
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ auto bluetoothSocketAidl = SharedRefBase::make<BluetoothSocket>();
+
+ fuzzService(bluetoothSocketAidl->asBinder().get(),
+ FuzzedDataProvider(data, size));
+
+ return 0;
+}