From 7d34fa17ab8602b591a0d91d2acb8f24707b336b Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 8 Dec 2016 18:10:48 -0800 Subject: recovery: Fix the argument parsing from COMMAND_FILE. Commit f0ed159f488c57c4ede0503443eb62fadfe0a831 didn't ensure mounting COMMAND_FILE (i.e. /cache) prior to reading. Also the first argument in COMMAND_FILE should not be dropped (unlike the first "recovery" argument in BCB message). Bug: 33431888 Test: Push /cache/recovery/command and recovery imag parses the arguments successfully. Change-Id: Ica3157a0bb03a2355315123354617eaf3fff15a4 --- recovery.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/recovery.cpp b/recovery.cpp index 5f1607553..e16f28c72 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -350,9 +350,12 @@ static std::vector get_args(const int argc, char** const argv) { // --- if that doesn't work, try the command file (if we have /cache). if (argc == 1 && has_cache) { std::string content; - if (android::base::ReadFileToString(COMMAND_FILE, &content)) { + if (ensure_path_mounted(COMMAND_FILE) == 0 && + android::base::ReadFileToString(COMMAND_FILE, &content)) { std::vector tokens = android::base::Split(content, "\n"); - for (auto it = tokens.begin() + 1; it != tokens.end(); it++) { + // All the arguments in COMMAND_FILE are needed (unlike the BCB message, + // COMMAND_FILE doesn't use filename as the first argument). + for (auto it = tokens.begin(); it != tokens.end(); it++) { // Skip empty and '\0'-filled tokens. if (!it->empty() && (*it)[0] != '\0') args.push_back(std::move(*it)); } -- cgit v1.2.3