Loading install.cpp +66 −68 Original line number Diff line number Diff line Loading @@ -36,9 +36,9 @@ #include <android-base/logging.h> #include <android-base/parsedouble.h> #include <android-base/parseint.h> #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <cutils/properties.h> #include <ziparchive/zip_archive.h> #include "common.h" Loading Loading @@ -139,8 +139,7 @@ update_binary_command(const char* path, ZipArchiveHandle zip, int retry_count, // Parses the metadata of the OTA package in |zip| and checks whether we are // allowed to accept this A/B package. Downgrading is not allowed unless // explicitly enabled in the package and only for incremental packages. static int check_newer_ab_build(ZipArchiveHandle zip) { static int check_newer_ab_build(ZipArchiveHandle zip) { std::string metadata_str; if (!read_metadata_from_package(zip, &metadata_str)) { return INSTALL_CORRUPT; Loading @@ -152,9 +151,8 @@ static int check_newer_ab_build(ZipArchiveHandle zip) metadata[line.substr(0, eq)] = line.substr(eq + 1); } } char value[PROPERTY_VALUE_MAX]; property_get("ro.product.device", value, ""); std::string value = android::base::GetProperty("ro.product.device", ""); const std::string& pkg_device = metadata["pre-device"]; if (pkg_device != value || pkg_device.empty()) { LOG(ERROR) << "Package is for product " << pkg_device << " but expected " << value; Loading @@ -163,7 +161,7 @@ static int check_newer_ab_build(ZipArchiveHandle zip) // We allow the package to not have any serialno, but if it has a non-empty // value it should match. property_get("ro.serialno", value, ""); value = android::base::GetProperty("ro.serialno", ""); const std::string& pkg_serial_no = metadata["serialno"]; if (!pkg_serial_no.empty() && pkg_serial_no != value) { LOG(ERROR) << "Package is for serial " << pkg_serial_no; Loading @@ -176,35 +174,35 @@ static int check_newer_ab_build(ZipArchiveHandle zip) } // Incremental updates should match the current build. property_get("ro.build.version.incremental", value, ""); value = android::base::GetProperty("ro.build.version.incremental", ""); const std::string& pkg_pre_build = metadata["pre-build-incremental"]; if (!pkg_pre_build.empty() && pkg_pre_build != value) { LOG(ERROR) << "Package is for source build " << pkg_pre_build << " but expected " << value; return INSTALL_ERROR; } property_get("ro.build.fingerprint", value, ""); value = android::base::GetProperty("ro.build.fingerprint", ""); const std::string& pkg_pre_build_fingerprint = metadata["pre-build"]; if (!pkg_pre_build_fingerprint.empty() && pkg_pre_build_fingerprint != value) { LOG(ERROR) << "Package is for source build " << pkg_pre_build_fingerprint << " but expected " << value; if (!pkg_pre_build_fingerprint.empty() && pkg_pre_build_fingerprint != value) { LOG(ERROR) << "Package is for source build " << pkg_pre_build_fingerprint << " but expected " << value; return INSTALL_ERROR; } // Check for downgrade version. int64_t build_timestamp = property_get_int64( "ro.build.date.utc", std::numeric_limits<int64_t>::max()); int64_t build_timestamp = android::base::GetIntProperty("ro.build.date.utc", std::numeric_limits<int64_t>::max()); int64_t pkg_post_timestamp = 0; // We allow to full update to the same version we are running, in case there // is a problem with the current copy of that version. if (metadata["post-timestamp"].empty() || !android::base::ParseInt(metadata["post-timestamp"].c_str(), &pkg_post_timestamp) || !android::base::ParseInt(metadata["post-timestamp"].c_str(), &pkg_post_timestamp) || pkg_post_timestamp < build_timestamp) { if (metadata["ota-downgrade"] != "yes") { LOG(ERROR) << "Update package is older than the current build, expected a build " "newer than timestamp " << build_timestamp << " but package has " "timestamp " << pkg_post_timestamp << " and downgrade not allowed."; "newer than timestamp " << build_timestamp << " but package has timestamp " << pkg_post_timestamp << " and downgrade not allowed."; return INSTALL_ERROR; } if (pkg_pre_build_fingerprint.empty()) { Loading recovery.cpp +12 −14 Original line number Diff line number Diff line Loading @@ -892,8 +892,8 @@ static bool check_wipe_package(size_t wipe_package_size) { // Extract metadata ZipArchiveHandle zip; int err = OpenArchiveFromMemory(reinterpret_cast<void*>(&wipe_package[0]), wipe_package.size(), "wipe_package", &zip); int err = OpenArchiveFromMemory(static_cast<void*>(&wipe_package[0]), wipe_package.size(), "wipe_package", &zip); if (err != 0) { LOG(ERROR) << "Can't open wipe package : " << ErrorCodeString(err); return false; Loading @@ -916,13 +916,11 @@ static bool check_wipe_package(size_t wipe_package_size) { ota_type_matched = true; } else if (android::base::StartsWith(line, "pre-device=")) { std::string device_type = line.substr(strlen("pre-device=")); char real_device_type[PROPERTY_VALUE_MAX]; property_get("ro.build.product", real_device_type, ""); std::string real_device_type = android::base::GetProperty("ro.build.product", ""); device_type_matched = (device_type == real_device_type); } else if (android::base::StartsWith(line, "serialno=")) { std::string serial_no = line.substr(strlen("serialno=")); char real_serial_no[PROPERTY_VALUE_MAX]; property_get("ro.serialno", real_serial_no, ""); std::string real_serial_no = android::base::GetProperty("ro.serialno", ""); has_serial_number = true; serial_number_matched = (serial_no == real_serial_no); } Loading Loading @@ -1361,10 +1359,10 @@ static void set_retry_bootloader_message(int retry_count, int argc, char** argv) } static bool bootreason_in_blacklist() { char bootreason[PROPERTY_VALUE_MAX]; if (property_get("ro.boot.bootreason", bootreason, nullptr) > 0) { std::string bootreason = android::base::GetProperty("ro.boot.bootreason", ""); if (!bootreason.empty()) { for (const auto& str : bootreason_blacklist) { if (strcasecmp(str.c_str(), bootreason) == 0) { if (strcasecmp(str.c_str(), bootreason.c_str()) == 0) { return true; } } Loading Loading
install.cpp +66 −68 Original line number Diff line number Diff line Loading @@ -36,9 +36,9 @@ #include <android-base/logging.h> #include <android-base/parsedouble.h> #include <android-base/parseint.h> #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <cutils/properties.h> #include <ziparchive/zip_archive.h> #include "common.h" Loading Loading @@ -139,8 +139,7 @@ update_binary_command(const char* path, ZipArchiveHandle zip, int retry_count, // Parses the metadata of the OTA package in |zip| and checks whether we are // allowed to accept this A/B package. Downgrading is not allowed unless // explicitly enabled in the package and only for incremental packages. static int check_newer_ab_build(ZipArchiveHandle zip) { static int check_newer_ab_build(ZipArchiveHandle zip) { std::string metadata_str; if (!read_metadata_from_package(zip, &metadata_str)) { return INSTALL_CORRUPT; Loading @@ -152,9 +151,8 @@ static int check_newer_ab_build(ZipArchiveHandle zip) metadata[line.substr(0, eq)] = line.substr(eq + 1); } } char value[PROPERTY_VALUE_MAX]; property_get("ro.product.device", value, ""); std::string value = android::base::GetProperty("ro.product.device", ""); const std::string& pkg_device = metadata["pre-device"]; if (pkg_device != value || pkg_device.empty()) { LOG(ERROR) << "Package is for product " << pkg_device << " but expected " << value; Loading @@ -163,7 +161,7 @@ static int check_newer_ab_build(ZipArchiveHandle zip) // We allow the package to not have any serialno, but if it has a non-empty // value it should match. property_get("ro.serialno", value, ""); value = android::base::GetProperty("ro.serialno", ""); const std::string& pkg_serial_no = metadata["serialno"]; if (!pkg_serial_no.empty() && pkg_serial_no != value) { LOG(ERROR) << "Package is for serial " << pkg_serial_no; Loading @@ -176,35 +174,35 @@ static int check_newer_ab_build(ZipArchiveHandle zip) } // Incremental updates should match the current build. property_get("ro.build.version.incremental", value, ""); value = android::base::GetProperty("ro.build.version.incremental", ""); const std::string& pkg_pre_build = metadata["pre-build-incremental"]; if (!pkg_pre_build.empty() && pkg_pre_build != value) { LOG(ERROR) << "Package is for source build " << pkg_pre_build << " but expected " << value; return INSTALL_ERROR; } property_get("ro.build.fingerprint", value, ""); value = android::base::GetProperty("ro.build.fingerprint", ""); const std::string& pkg_pre_build_fingerprint = metadata["pre-build"]; if (!pkg_pre_build_fingerprint.empty() && pkg_pre_build_fingerprint != value) { LOG(ERROR) << "Package is for source build " << pkg_pre_build_fingerprint << " but expected " << value; if (!pkg_pre_build_fingerprint.empty() && pkg_pre_build_fingerprint != value) { LOG(ERROR) << "Package is for source build " << pkg_pre_build_fingerprint << " but expected " << value; return INSTALL_ERROR; } // Check for downgrade version. int64_t build_timestamp = property_get_int64( "ro.build.date.utc", std::numeric_limits<int64_t>::max()); int64_t build_timestamp = android::base::GetIntProperty("ro.build.date.utc", std::numeric_limits<int64_t>::max()); int64_t pkg_post_timestamp = 0; // We allow to full update to the same version we are running, in case there // is a problem with the current copy of that version. if (metadata["post-timestamp"].empty() || !android::base::ParseInt(metadata["post-timestamp"].c_str(), &pkg_post_timestamp) || !android::base::ParseInt(metadata["post-timestamp"].c_str(), &pkg_post_timestamp) || pkg_post_timestamp < build_timestamp) { if (metadata["ota-downgrade"] != "yes") { LOG(ERROR) << "Update package is older than the current build, expected a build " "newer than timestamp " << build_timestamp << " but package has " "timestamp " << pkg_post_timestamp << " and downgrade not allowed."; "newer than timestamp " << build_timestamp << " but package has timestamp " << pkg_post_timestamp << " and downgrade not allowed."; return INSTALL_ERROR; } if (pkg_pre_build_fingerprint.empty()) { Loading
recovery.cpp +12 −14 Original line number Diff line number Diff line Loading @@ -892,8 +892,8 @@ static bool check_wipe_package(size_t wipe_package_size) { // Extract metadata ZipArchiveHandle zip; int err = OpenArchiveFromMemory(reinterpret_cast<void*>(&wipe_package[0]), wipe_package.size(), "wipe_package", &zip); int err = OpenArchiveFromMemory(static_cast<void*>(&wipe_package[0]), wipe_package.size(), "wipe_package", &zip); if (err != 0) { LOG(ERROR) << "Can't open wipe package : " << ErrorCodeString(err); return false; Loading @@ -916,13 +916,11 @@ static bool check_wipe_package(size_t wipe_package_size) { ota_type_matched = true; } else if (android::base::StartsWith(line, "pre-device=")) { std::string device_type = line.substr(strlen("pre-device=")); char real_device_type[PROPERTY_VALUE_MAX]; property_get("ro.build.product", real_device_type, ""); std::string real_device_type = android::base::GetProperty("ro.build.product", ""); device_type_matched = (device_type == real_device_type); } else if (android::base::StartsWith(line, "serialno=")) { std::string serial_no = line.substr(strlen("serialno=")); char real_serial_no[PROPERTY_VALUE_MAX]; property_get("ro.serialno", real_serial_no, ""); std::string real_serial_no = android::base::GetProperty("ro.serialno", ""); has_serial_number = true; serial_number_matched = (serial_no == real_serial_no); } Loading Loading @@ -1361,10 +1359,10 @@ static void set_retry_bootloader_message(int retry_count, int argc, char** argv) } static bool bootreason_in_blacklist() { char bootreason[PROPERTY_VALUE_MAX]; if (property_get("ro.boot.bootreason", bootreason, nullptr) > 0) { std::string bootreason = android::base::GetProperty("ro.boot.bootreason", ""); if (!bootreason.empty()) { for (const auto& str : bootreason_blacklist) { if (strcasecmp(str.c_str(), bootreason) == 0) { if (strcasecmp(str.c_str(), bootreason.c_str()) == 0) { return true; } } Loading