summaryrefslogtreecommitdiffstats
path: root/applypatch
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-07-10 08:19:19 +0200
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-07-10 08:19:19 +0200
commite02cbaaa629444772cdf92e35f1b2867084d30f9 (patch)
tree9ee75d9e178f99e7eb34a7b47e98e06f6d6e79ab /applypatch
parentMerge "applypatch: Fix a potential nullptr dereferencing." (diff)
parentapplypatch: Restrict applypatch_check to eMMC targets. (diff)
downloadandroid_bootable_recovery-e02cbaaa629444772cdf92e35f1b2867084d30f9.tar
android_bootable_recovery-e02cbaaa629444772cdf92e35f1b2867084d30f9.tar.gz
android_bootable_recovery-e02cbaaa629444772cdf92e35f1b2867084d30f9.tar.bz2
android_bootable_recovery-e02cbaaa629444772cdf92e35f1b2867084d30f9.tar.lz
android_bootable_recovery-e02cbaaa629444772cdf92e35f1b2867084d30f9.tar.xz
android_bootable_recovery-e02cbaaa629444772cdf92e35f1b2867084d30f9.tar.zst
android_bootable_recovery-e02cbaaa629444772cdf92e35f1b2867084d30f9.zip
Diffstat (limited to 'applypatch')
-rw-r--r--applypatch/applypatch.cpp22
-rw-r--r--applypatch/include/applypatch/applypatch.h7
2 files changed, 16 insertions, 13 deletions
diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp
index 69928bcfb..fc29493b4 100644
--- a/applypatch/applypatch.cpp
+++ b/applypatch/applypatch.cpp
@@ -376,24 +376,26 @@ static int FindMatchingPatch(const uint8_t* sha1, const std::vector<std::string>
return -1;
}
-int applypatch_check(const char* filename, const std::vector<std::string>& patch_sha1s) {
- // It's okay to specify no SHA-1s; the check will pass if the LoadFileContents is successful.
- // (Useful for reading partitions, where the filename encodes the SHA-1s; no need to check them
- // twice.)
+int applypatch_check(const std::string& filename, const std::vector<std::string>& sha1s) {
+ if (!android::base::StartsWith(filename, "EMMC:")) {
+ return 1;
+ }
+
+ // The check will pass if LoadPartitionContents is successful, because the filename already
+ // encodes the desired SHA-1s.
FileContents file;
- if (LoadFileContents(filename, &file) != 0 ||
- (!patch_sha1s.empty() && FindMatchingPatch(file.sha1, patch_sha1s) < 0)) {
+ if (LoadPartitionContents(filename, &file) != 0) {
LOG(INFO) << "\"" << filename << "\" doesn't have any of expected SHA-1 sums; checking cache";
- // If the source file is missing or corrupted, it might be because we were killed in the middle
- // of patching it. A copy should have been made in cache_temp_source. If that file exists and
- // matches the SHA-1 we're looking for, the check still passes.
+ // If the partition is corrupted, it might be because we were killed in the middle of patching
+ // it. A copy should have been made in cache_temp_source. If that file exists and matches the
+ // SHA-1 we're looking for, the check still passes.
if (LoadFileContents(Paths::Get().cache_temp_source(), &file) != 0) {
LOG(ERROR) << "Failed to load cache file";
return 1;
}
- if (FindMatchingPatch(file.sha1, patch_sha1s) < 0) {
+ if (FindMatchingPatch(file.sha1, sha1s) < 0) {
LOG(ERROR) << "The cache bits don't match any SHA-1 for \"" << filename << "\"";
return 1;
}
diff --git a/applypatch/include/applypatch/applypatch.h b/applypatch/include/applypatch/applypatch.h
index f074e3681..92db59c3a 100644
--- a/applypatch/include/applypatch/applypatch.h
+++ b/applypatch/include/applypatch/applypatch.h
@@ -78,9 +78,10 @@ int applypatch(const char* source_filename, const char* target_filename,
const std::vector<std::string>& patch_sha1s,
const std::vector<std::unique_ptr<Value>>& patch_data, const Value* bonus_data);
-// Returns 0 if the contents of the file or the cached file match any of the given SHA-1's. Returns
-// nonzero otherwise.
-int applypatch_check(const char* filename, const std::vector<std::string>& patch_sha1s);
+// Returns 0 if the contents of the eMMC target or the cached file match any of the given SHA-1's.
+// Returns nonzero otherwise. 'filename' must refer to an eMMC partition target. It would only use
+// 'sha1s' to find a match on /cache if the hashes embedded in the filename fail to match.
+int applypatch_check(const std::string& filename, const std::vector<std::string>& sha1s);
// Flashes a given image to the target partition. It verifies the target cheksum first, and will
// return if target already has the desired hash. Otherwise it checks the checksum of the given