aboutsummaryrefslogtreecommitdiff
path: root/applypatch
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-07-09 15:16:13 -0700
committerTao Bao <tbao@google.com>2018-07-09 15:22:35 -0700
commit7ea515e6fcf01ec6ea35e28248d9246ce0be2f72 (patch)
tree2bbb96f9a7022325c8097d8f063a31d685c4708a /applypatch
parentc059b6c1c66d802196874b1ad14c62f33774a87a (diff)
downloadrecovery-7ea515e6fcf01ec6ea35e28248d9246ce0be2f72.tar.gz
applypatch: Fix a potential nullptr dereferencing.
Note that the code exists in debugging path only, and won't be hit unless device has flaky flash. Test: Run recovery_unit_test and recovery_component_test on marlin. Change-Id: I0c71adc271f08f00e3eabd9d14cd8af3186c5bae
Diffstat (limited to 'applypatch')
-rw-r--r--applypatch/applypatch.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp
index e6fd5f6a..69928bcf 100644
--- a/applypatch/applypatch.cpp
+++ b/applypatch/applypatch.cpp
@@ -622,10 +622,13 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr
SHA1(reinterpret_cast<const uint8_t*>(patch->data.data()), patch->data.size(), patch_digest);
LOG(ERROR) << "patch size " << patch->data.size() << " SHA-1 " << short_sha1(patch_digest);
- uint8_t bonus_digest[SHA_DIGEST_LENGTH];
- SHA1(reinterpret_cast<const uint8_t*>(bonus_data->data.data()), bonus_data->data.size(),
- bonus_digest);
- LOG(ERROR) << "bonus size " << bonus_data->data.size() << " SHA-1 " << short_sha1(bonus_digest);
+ if (bonus_data != nullptr) {
+ uint8_t bonus_digest[SHA_DIGEST_LENGTH];
+ SHA1(reinterpret_cast<const uint8_t*>(bonus_data->data.data()), bonus_data->data.size(),
+ bonus_digest);
+ LOG(ERROR) << "bonus size " << bonus_data->data.size() << " SHA-1 "
+ << short_sha1(bonus_digest);
+ }
// TODO(b/67849209) Remove after debugging the unit test flakiness.
if (android::base::GetMinimumLogSeverity() <= android::base::LogSeverity::DEBUG) {