From edf1b15fefca1fa43d628a9c79d351dd960a002f Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 24 Oct 2016 16:08:28 -0700 Subject: applypatch: Fix the bug when constructing VAL_BLOB. When constructing std::string from C-string, the string may be truncated at null char. Use range constructor instead. Bug: 32380016 Test: Use applypatch to install a previously failed recovery image. Change-Id: Id3e2afb4a810594243cd21db526933d1fea5044b --- applypatch/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/applypatch/main.cpp b/applypatch/main.cpp index a3a45d06f..294f7ee21 100644 --- a/applypatch/main.cpp +++ b/applypatch/main.cpp @@ -99,7 +99,7 @@ static int PatchMode(int argc, char** argv) { return 1; } bonus.type = VAL_BLOB; - bonus.data = reinterpret_cast(bonusFc.data.data()); + bonus.data = std::string(bonusFc.data.cbegin(), bonusFc.data.cend()); argc -= 2; argv += 2; } @@ -132,7 +132,8 @@ static int PatchMode(int argc, char** argv) { std::vector patches; std::vector patch_ptrs; for (size_t i = 0; i < files.size(); ++i) { - patches.push_back(Value(VAL_BLOB, reinterpret_cast(files[i].data.data()))); + patches.push_back(Value(VAL_BLOB, + std::string(files[i].data.cbegin(), files[i].data.cend()))); patch_ptrs.push_back(&patches[i]); } return applypatch(argv[1], argv[2], argv[3], target_size, -- cgit v1.2.3