From 643ddd99dfa3d90ebcb1f8396a2375ba7e80633c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 30 Aug 2019 12:35:02 -0700 Subject: boot_control: Don't allow current_slot_ to be -1. If the HAL is run on a non-A/B device, it does not fail gracefully; it will segfault because the current_slot is -1 and methods do not protect against this. Instead, have Init() fail if we can't determine the current slot. Bug: 130078382 Test: vts tests Change-Id: I2d3094518a842b1a764427d2da9d46781a9f26da --- boot_control/libboot_control.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/boot_control/libboot_control.cpp b/boot_control/libboot_control.cpp index 8b44d5d1c..fa7dc47ef 100644 --- a/boot_control/libboot_control.cpp +++ b/boot_control/libboot_control.cpp @@ -196,6 +196,10 @@ bool BootControl::Init() { // was not set (from either the command line or the device tree), we can later // initialize it from the bootloader_control struct. std::string suffix_prop = android::base::GetProperty("ro.boot.slot_suffix", ""); + if (suffix_prop.empty()) { + LOG(ERROR) << "Slot suffix property is not set"; + return false; + } current_slot_ = SlotSuffixToIndex(suffix_prop.c_str()); std::string err; -- cgit v1.2.3