Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Unified Diff: delta_performer.cc

Issue 5121008: AU: Check the delta magic and fail on mismatch. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: fix comment Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | delta_performer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: delta_performer.cc
diff --git a/delta_performer.cc b/delta_performer.cc
index e14ad4ec03b07b87d69cc30a7ebe3ecc33a5d89d..a5b7a729f2618fa0bee9f1fbe805140e3ae9ccec 100644
--- a/delta_performer.cc
+++ b/delta_performer.cc
@@ -146,10 +146,6 @@ bool DeltaPerformer::OpenKernel(const char* kernel_path) {
}
int DeltaPerformer::Close() {
- if (!buffer_.empty()) {
- LOG(ERROR) << "Called Close() while buffer not empty!";
- return -1;
- }
int err = 0;
if (close(kernel_fd_) == -1) {
err = errno;
@@ -160,8 +156,14 @@ int DeltaPerformer::Close() {
PLOG(ERROR) << "Unable to close rootfs fd:";
}
LOG_IF(ERROR, !hash_calculator_.Finalize()) << "Unable to finalize the hash.";
- fd_ = -2; // Set so that isn't not valid AND calls to Open() will fail.
+ fd_ = -2; // Set to invalid so that calls to Open() will fail.
path_ = "";
+ if (!buffer_.empty()) {
+ LOG(ERROR) << "Called Close() while buffer not empty!";
+ if (err >= 0) {
+ err = 1;
+ }
+ }
return -err;
}
@@ -201,12 +203,15 @@ ssize_t DeltaPerformer::Write(const void* bytes, size_t count) {
buffer_.insert(buffer_.end(), c_bytes, c_bytes + count);
if (!manifest_valid_) {
- // See if we have enough bytes for the manifest yet
if (buffer_.size() < strlen(kDeltaMagic) +
kDeltaVersionLength + kDeltaProtobufLengthLength) {
- // Don't have enough bytes to even know the protobuf length
+ // Don't have enough bytes to know the protobuf length.
return count;
}
+ if (memcmp(buffer_.data(), kDeltaMagic, strlen(kDeltaMagic)) != 0) {
+ LOG(ERROR) << "Bad payload format -- invalid delta magic.";
+ return -EINVAL;
+ }
uint64_t protobuf_length;
COMPILE_ASSERT(sizeof(protobuf_length) == kDeltaProtobufLengthLength,
protobuf_length_size_mismatch);
« no previous file with comments | « no previous file | delta_performer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698