summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-06-09 11:32:03 +0200
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-06-09 11:32:03 +0200
commit44e8b33826e44bf59a7d331f1574038c0b1ed8f3 (patch)
tree84de8c12121c2a8979b2bfdde2486a8f0ef9e316
parentSnap for 4829746 from 4b5dc30a92ce528b65b99da6aad0bfb45ebafa8a to qt-release (diff)
parentMerge "updater: Remove the redundant check on line count." am: 4a8f5ec06d am: 165a197cdf (diff)
downloadandroid_bootable_recovery-44e8b33826e44bf59a7d331f1574038c0b1ed8f3.tar
android_bootable_recovery-44e8b33826e44bf59a7d331f1574038c0b1ed8f3.tar.gz
android_bootable_recovery-44e8b33826e44bf59a7d331f1574038c0b1ed8f3.tar.bz2
android_bootable_recovery-44e8b33826e44bf59a7d331f1574038c0b1ed8f3.tar.lz
android_bootable_recovery-44e8b33826e44bf59a7d331f1574038c0b1ed8f3.tar.xz
android_bootable_recovery-44e8b33826e44bf59a7d331f1574038c0b1ed8f3.tar.zst
android_bootable_recovery-44e8b33826e44bf59a7d331f1574038c0b1ed8f3.zip
-rw-r--r--tests/component/updater_test.cpp23
-rw-r--r--updater/blockimg.cpp12
2 files changed, 24 insertions, 11 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index 6f3a3a2a7..fe4f45e15 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -100,7 +100,8 @@ static void BuildUpdatePackage(const PackageEntries& entries, int fd) {
}
static void RunBlockImageUpdate(bool is_verify, const PackageEntries& entries,
- const std::string& image_file, const std::string& result) {
+ const std::string& image_file, const std::string& result,
+ CauseCode cause_code = kNoCause) {
CHECK(entries.find("transfer_list") != entries.end());
// Build the update package.
@@ -124,7 +125,7 @@ static void RunBlockImageUpdate(bool is_verify, const PackageEntries& entries,
std::string script = is_verify ? "block_image_verify" : "block_image_update";
script += R"((")" + image_file + R"(", package_extract_file("transfer_list"), ")" + new_data +
R"(", "patch_data"))";
- expect(result.c_str(), script.c_str(), kNoCause, &updater_info);
+ expect(result.c_str(), script.c_str(), cause_code, &updater_info);
ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
CloseArchive(handle);
@@ -504,6 +505,24 @@ TEST_F(UpdaterTest, show_progress) {
ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
}
+TEST_F(UpdaterTest, block_image_update_parsing_error) {
+ std::vector<std::string> transfer_list{
+ // clang-format off
+ "4",
+ "2",
+ "0",
+ // clang-format on
+ };
+
+ PackageEntries entries{
+ { "new_data", "" },
+ { "patch_data", "" },
+ { "transfer_list", android::base::Join(transfer_list, '\n') },
+ };
+
+ RunBlockImageUpdate(false, entries, image_file_, "", kArgsParsingFailure);
+}
+
TEST_F(UpdaterTest, block_image_update_patch_data) {
std::string src_content = std::string(4096, 'a') + std::string(4096, 'c');
std::string tgt_content = std::string(4096, 'b') + std::string(4096, 'd');
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp
index f2811bccf..1646b7c17 100644
--- a/updater/blockimg.cpp
+++ b/updater/blockimg.cpp
@@ -1628,9 +1628,10 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
}
}
+ static constexpr size_t kTransferListHeaderLines = 4;
std::vector<std::string> lines = android::base::Split(transfer_list_value->data, "\n");
- if (lines.size() < 2) {
- ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zd]",
+ if (lines.size() < kTransferListHeaderLines) {
+ ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zu]",
lines.size());
return StringValue("");
}
@@ -1654,12 +1655,6 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
return StringValue("t");
}
- if (lines.size() < 4) {
- ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zu]",
- lines.size());
- return StringValue("");
- }
-
// Third line is how many stash entries are needed simultaneously.
LOG(INFO) << "maximum stash entries " << lines[2];
@@ -1698,7 +1693,6 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
int rc = -1;
- static constexpr size_t kTransferListHeaderLines = 4;
// Subsequent lines are all individual transfer commands
for (size_t i = kTransferListHeaderLines; i < lines.size(); i++) {
const std::string& line = lines[i];