summaryrefslogtreecommitdiffstats
path: root/install
diff options
context:
space:
mode:
Diffstat (limited to 'install')
-rw-r--r--install/Android.bp9
-rw-r--r--install/install.cpp42
-rw-r--r--install/snapshot_utils.cpp4
-rw-r--r--install/verifier.cpp8
-rw-r--r--install/wipe_data.cpp8
-rw-r--r--install/wipe_device.cpp9
6 files changed, 64 insertions, 16 deletions
diff --git a/install/Android.bp b/install/Android.bp
index bed3bc504..8c88bd01e 100644
--- a/install/Android.bp
+++ b/install/Android.bp
@@ -12,6 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "bootable_recovery_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["bootable_recovery_license"],
+}
+
cc_defaults {
name: "libinstall_defaults",
diff --git a/install/install.cpp b/install/install.cpp
index d404997dc..1b220cb39 100644
--- a/install/install.cpp
+++ b/install/install.cpp
@@ -67,14 +67,17 @@ static_assert(kRecoveryApiVersion == RECOVERY_API_VERSION, "Mismatching recovery
// Default allocation of progress bar segments to operations
static constexpr int VERIFICATION_PROGRESS_TIME = 60;
static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25;
-
+// The charater used to separate dynamic fingerprints. e.x. sargo|aosp-sargo
+static const char* FINGERPRING_SEPARATOR = "|";
static std::condition_variable finish_log_temperature;
+static bool isInStringList(const std::string& target_token, const std::string& str_list,
+ const std::string& deliminator);
bool ReadMetadataFromPackage(ZipArchiveHandle zip, std::map<std::string, std::string>* metadata) {
CHECK(metadata != nullptr);
static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata";
- ZipEntry entry;
+ ZipEntry64 entry;
if (FindEntry(zip, METADATA_PATH, &entry) != 0) {
LOG(ERROR) << "Failed to find " << METADATA_PATH;
return false;
@@ -151,7 +154,8 @@ static bool CheckAbSpecificMetadata(const std::map<std::string, std::string>& me
auto device_fingerprint = android::base::GetProperty("ro.build.fingerprint", "");
auto pkg_pre_build_fingerprint = get_value(metadata, "pre-build");
- if (!pkg_pre_build_fingerprint.empty() && pkg_pre_build_fingerprint != device_fingerprint) {
+ if (!pkg_pre_build_fingerprint.empty() &&
+ !isInStringList(device_fingerprint, pkg_pre_build_fingerprint, FINGERPRING_SEPARATOR)) {
LOG(ERROR) << "Package is for source build " << pkg_pre_build_fingerprint << " but expected "
<< device_fingerprint;
return false;
@@ -199,7 +203,8 @@ bool CheckPackageMetadata(const std::map<std::string, std::string>& metadata, Ot
auto device = android::base::GetProperty("ro.product.device", "");
auto pkg_device = get_value(metadata, "pre-device");
- if (pkg_device != device || pkg_device.empty()) {
+ // device name can be a | separated list, so need to check
+ if (pkg_device.empty() || !isInStringList(device, pkg_device, FINGERPRING_SEPARATOR)) {
LOG(ERROR) << "Package is for product " << pkg_device << " but expected " << device;
return false;
}
@@ -236,12 +241,18 @@ bool SetUpAbUpdateCommands(const std::string& package, ZipArchiveHandle zip, int
// For A/B updates we extract the payload properties to a buffer and obtain the RAW payload offset
// in the zip file.
static constexpr const char* AB_OTA_PAYLOAD_PROPERTIES = "payload_properties.txt";
- ZipEntry properties_entry;
+ ZipEntry64 properties_entry;
if (FindEntry(zip, AB_OTA_PAYLOAD_PROPERTIES, &properties_entry) != 0) {
LOG(ERROR) << "Failed to find " << AB_OTA_PAYLOAD_PROPERTIES;
return false;
}
- uint32_t properties_entry_length = properties_entry.uncompressed_length;
+ auto properties_entry_length = properties_entry.uncompressed_length;
+ if (properties_entry_length > std::numeric_limits<size_t>::max()) {
+ LOG(ERROR) << "Failed to extract " << AB_OTA_PAYLOAD_PROPERTIES
+ << " because's uncompressed size exceeds size of address space. "
+ << properties_entry_length;
+ return false;
+ }
std::vector<uint8_t> payload_properties(properties_entry_length);
int32_t err =
ExtractToMemory(zip, &properties_entry, payload_properties.data(), properties_entry_length);
@@ -251,7 +262,7 @@ bool SetUpAbUpdateCommands(const std::string& package, ZipArchiveHandle zip, int
}
static constexpr const char* AB_OTA_PAYLOAD = "payload.bin";
- ZipEntry payload_entry;
+ ZipEntry64 payload_entry;
if (FindEntry(zip, AB_OTA_PAYLOAD, &payload_entry) != 0) {
LOG(ERROR) << "Failed to find " << AB_OTA_PAYLOAD;
return false;
@@ -273,7 +284,7 @@ bool SetUpNonAbUpdateCommands(const std::string& package, ZipArchiveHandle zip,
// In non-A/B updates we extract the update binary from the package.
static constexpr const char* UPDATE_BINARY_NAME = "META-INF/com/google/android/update-binary";
- ZipEntry binary_entry;
+ ZipEntry64 binary_entry;
if (FindEntry(zip, UPDATE_BINARY_NAME, &binary_entry) != 0) {
LOG(ERROR) << "Failed to find update binary " << UPDATE_BINARY_NAME;
return false;
@@ -699,3 +710,18 @@ bool SetupPackageMount(const std::string& package_path, bool* should_use_fuse) {
}
return true;
}
+
+// Check if `target_token` is in string `str_list`, where `str_list` is expected to be a
+// list delimited by `deliminator`
+// E.X. isInStringList("a", "a|b|c|d", "|") => true
+// E.X. isInStringList("abc", "abc", "|") => true
+static bool isInStringList(const std::string& target_token, const std::string& str_list,
+ const std::string& deliminator) {
+ if (target_token.length() > str_list.length()) {
+ return false;
+ } else if (target_token.length() == str_list.length() || deliminator.length() == 0) {
+ return target_token == str_list;
+ }
+ auto&& list = android::base::Split(str_list, deliminator);
+ return std::find(list.begin(), list.end(), target_token) != list.end();
+}
diff --git a/install/snapshot_utils.cpp b/install/snapshot_utils.cpp
index 7235e67c8..336e50f89 100644
--- a/install/snapshot_utils.cpp
+++ b/install/snapshot_utils.cpp
@@ -32,7 +32,7 @@ bool FinishPendingSnapshotMerges(Device* device) {
}
RecoveryUI* ui = device->GetUI();
- auto sm = SnapshotManager::NewForFirstStageMount();
+ auto sm = SnapshotManager::New();
if (!sm) {
ui->Print("Could not create SnapshotManager.\n");
return false;
@@ -57,7 +57,7 @@ bool CreateSnapshotPartitions() {
return true;
}
- auto sm = SnapshotManager::NewForFirstStageMount();
+ auto sm = SnapshotManager::New();
if (!sm) {
// SnapshotManager could not be created. The device is still in a
// consistent state and can continue with the mounting of the existing
diff --git a/install/verifier.cpp b/install/verifier.cpp
index ab750442d..3f0260138 100644
--- a/install/verifier.cpp
+++ b/install/verifier.cpp
@@ -321,8 +321,14 @@ static std::vector<Certificate> IterateZipEntriesAndSearchForKeys(const ZipArchi
std::vector<Certificate> result;
std::string_view name;
- ZipEntry entry;
+ ZipEntry64 entry;
while ((iter_status = Next(cookie, &entry, &name)) == 0) {
+ if (entry.uncompressed_length > std::numeric_limits<size_t>::max()) {
+ LOG(ERROR) << "Failed to extract " << name
+ << " because's uncompressed size exceeds size of address space. "
+ << entry.uncompressed_length;
+ return {};
+ }
std::vector<uint8_t> pem_content(entry.uncompressed_length);
if (int32_t extract_status =
ExtractToMemory(handle, &entry, pem_content.data(), pem_content.size());
diff --git a/install/wipe_data.cpp b/install/wipe_data.cpp
index 287208583..4eecf72c6 100644
--- a/install/wipe_data.cpp
+++ b/install/wipe_data.cpp
@@ -41,9 +41,6 @@ static bool EraseVolume(const char* volume, RecoveryUI* ui, bool convert_fbe) {
bool is_cache = (strcmp(volume, CACHE_ROOT) == 0);
bool is_data = (strcmp(volume, DATA_ROOT) == 0);
- ui->SetBackground(RecoveryUI::ERASING);
- ui->SetProgressType(RecoveryUI::INDETERMINATE);
-
std::vector<saved_log_file> log_files;
if (is_cache) {
// If we're reformatting /cache, we load any past logs (i.e. "/cache/recovery/last_*") and the
@@ -97,6 +94,9 @@ bool WipeCache(RecoveryUI* ui, const std::function<bool()>& confirm_func) {
}
ui->Print("\n-- Wiping cache...\n");
+ ui->SetBackground(RecoveryUI::ERASING);
+ ui->SetProgressType(RecoveryUI::INDETERMINATE);
+
bool success = EraseVolume("/cache", ui, false);
ui->Print("Cache wipe %s.\n", success ? "complete" : "failed");
return success;
@@ -105,6 +105,8 @@ bool WipeCache(RecoveryUI* ui, const std::function<bool()>& confirm_func) {
bool WipeData(Device* device, bool convert_fbe) {
RecoveryUI* ui = device->GetUI();
ui->Print("\n-- Wiping data...\n");
+ ui->SetBackground(RecoveryUI::ERASING);
+ ui->SetProgressType(RecoveryUI::INDETERMINATE);
if (!FinishPendingSnapshotMerges(device)) {
ui->Print("Unable to check update status or complete merge, cannot wipe partitions.\n");
diff --git a/install/wipe_device.cpp b/install/wipe_device.cpp
index 89d5d31a3..915c87b45 100644
--- a/install/wipe_device.cpp
+++ b/install/wipe_device.cpp
@@ -49,9 +49,14 @@ std::vector<std::string> GetWipePartitionList(Package* wipe_package) {
constexpr char RECOVERY_WIPE_ENTRY_NAME[] = "recovery.wipe";
std::string partition_list_content;
- ZipEntry entry;
+ ZipEntry64 entry;
if (FindEntry(zip, RECOVERY_WIPE_ENTRY_NAME, &entry) == 0) {
- uint32_t length = entry.uncompressed_length;
+ auto length = entry.uncompressed_length;
+ if (length > std::numeric_limits<size_t>::max()) {
+ LOG(ERROR) << "Failed to extract " << RECOVERY_WIPE_ENTRY_NAME
+ << " because's uncompressed size exceeds size of address space. " << length;
+ return {};
+ }
partition_list_content = std::string(length, '\0');
if (auto err = ExtractToMemory(
zip, &entry, reinterpret_cast<uint8_t*>(partition_list_content.data()), length);