Check for null system device
Check for null device in gsi service and return invalid fd
when device is null. Adding checks for invalid fd.
Test: atest vts_gsi_boot_test
Test: m gsi_service_fuzzer && adb sync data && adb shell /data/fuzz/x86_64/gsi_service_fuzzer/gsi_service_fuzzer -runs=10000
Bug: 313514072
Change-Id: I89bda8a48267e98f180d273d338aac6c869f9876
diff --git a/gsi_service.cpp b/gsi_service.cpp
index 6f2428d..224f520 100644
--- a/gsi_service.cpp
+++ b/gsi_service.cpp
@@ -506,6 +506,12 @@
return binder::Status::ok();
}
int fd = installer_->GetPartitionFd();
+ if (fd == -1) {
+ LOG(ERROR) << "Failed to get partition fd";
+ *_aidl_return = INSTALL_ERROR_GENERIC;
+ return binder::Status::ok();
+ }
+
if (!GetAvbPublicKeyFromFd(fd, dst)) {
LOG(ERROR) << "Failed to extract AVB public key";
*_aidl_return = INSTALL_ERROR_GENERIC;
diff --git a/partition_installer.cpp b/partition_installer.cpp
index ebd3b64..ebfb329 100644
--- a/partition_installer.cpp
+++ b/partition_installer.cpp
@@ -256,6 +256,9 @@
}
int PartitionInstaller::GetPartitionFd() {
+ if (!system_device_) {
+ return -1;
+ }
return system_device_->fd();
}