init: fix undefined behavior in ExecuteCommand

ExecuteCommand may change command_ vector which leads undefined behavior
This bug is found when adding logs in ExecuteCommand printing our Command class fields

Bug: 32838381
Test: on emulator
Change-Id: I96468bd2192ca80013871a3a6ac4132149363fff
This commit is contained in:
Wei Wang 2016-11-16 12:08:30 -08:00
parent 8b1d526a72
commit d67a4abc64
2 changed files with 7 additions and 4 deletions

View File

@ -105,7 +105,10 @@ std::size_t Action::NumCommands() const {
}
void Action::ExecuteOneCommand(std::size_t command) const {
ExecuteCommand(commands_[command]);
// We need a copy here since some Command execution may result in
// changing commands_ vector by importing .rc files through parser
Command cmd = commands_[command];
ExecuteCommand(cmd);
}
void Action::ExecuteAllCommands() const {

View File

@ -589,9 +589,9 @@ static int do_mount_all(const std::vector<std::string>& args) {
for (na = args.size() - 1; na > 1; --na) {
if (args[na] == "--early") {
path_arg_end = na;
queue_event = false;
mount_mode = MOUNT_MODE_EARLY;
path_arg_end = na;
queue_event = false;
mount_mode = MOUNT_MODE_EARLY;
} else if (args[na] == "--late") {
path_arg_end = na;
import_rc = false;