AutomationController: Bug fix for string use after free.
Change-Id: Iaa39ed9c21e60b3c069d3b0627e9401d82aca5f7
diff --git a/android-qemu2-glue/qemu-automation-agent-impl.cpp b/android-qemu2-glue/qemu-automation-agent-impl.cpp
index da2d767..c6c3ff5 100644
--- a/android-qemu2-glue/qemu-automation-agent-impl.cpp
+++ b/android-qemu2-glue/qemu-automation-agent-impl.cpp
@@ -46,8 +46,7 @@
AutomationController::get().setMacroName(macroName, filename);
}
-static android::base::StringView get_macro_name(
- android::base::StringView filename) {
+static std::string get_macro_name(android::base::StringView filename) {
return AutomationController::get().getMacroName(filename);
}
diff --git a/android/android-emu/android/automation/AutomationController.cpp b/android/android-emu/android/automation/AutomationController.cpp
index 716a39b..0e9694a 100644
--- a/android/android-emu/android/automation/AutomationController.cpp
+++ b/android/android-emu/android/automation/AutomationController.cpp
@@ -372,7 +372,7 @@
// MacroUI helper functions.
void setMacroName(StringView macroName, StringView filename) override;
- StringView getMacroName(StringView filename) override;
+ std::string getMacroName(StringView filename) override;
uint64_t getDurationNs(StringView filename) override;
ReplayResult replayInitialState(StringView state) override;
@@ -714,7 +714,7 @@
return Ok();
}
-StringView AutomationControllerImpl::getMacroName(StringView filename) {
+std::string AutomationControllerImpl::getMacroName(StringView filename) {
std::string path = filename;
if (!PathUtils::isAbsolute(path)) {
path = PathUtils::join(System::get()->getHomeDirectory(), filename);
@@ -731,9 +731,7 @@
return "";
}
- // Cast to std::string before casting to Stringview.
- const std::string result = header.name();
- return result;
+ return header.name();
}
uint64_t AutomationControllerImpl::getDurationNs(StringView filename) {
diff --git a/android/android-emu/android/automation/AutomationController.h b/android/android-emu/android/automation/AutomationController.h
index bb683e4..71d5b3f 100644
--- a/android/android-emu/android/automation/AutomationController.h
+++ b/android/android-emu/android/automation/AutomationController.h
@@ -137,8 +137,7 @@
android::base::StringView filename) = 0;
// Get the macro name from the header of a file.
- virtual android::base::StringView getMacroName(
- android::base::StringView filename) = 0;
+ virtual std::string getMacroName(android::base::StringView filename) = 0;
// Get the duration in nanoseconds from a file.
virtual uint64_t getDurationNs(android::base::StringView filename) = 0;
diff --git a/android/android-emu/android/emulation/control/automation_agent.h b/android/android-emu/android/emulation/control/automation_agent.h
index a8e402700..db4f441 100644
--- a/android/android-emu/android/emulation/control/automation_agent.h
+++ b/android/android-emu/android/emulation/control/automation_agent.h
@@ -43,7 +43,7 @@
void (*setMacroName)(StringView macroName, StringView filename);
// Get the macro name from the header of a file.
- StringView (*getMacroName)(StringView filename);
+ std::string (*getMacroName)(StringView filename);
// Get the duration in nanoseconds from a file.
uint64_t (*getDurationNs)(StringView filename);
diff --git a/android/android-emu/android/skin/qt/extended-pages/record-macro-page.cpp b/android/android-emu/android/skin/qt/extended-pages/record-macro-page.cpp
index acb8671..8eb05c2 100644
--- a/android/android-emu/android/skin/qt/extended-pages/record-macro-page.cpp
+++ b/android/android-emu/android/skin/qt/extended-pages/record-macro-page.cpp
@@ -783,7 +783,7 @@
mLengths[macroName] = qs;
macroSavedItem->setDisplayTime(mLengths[macroName]);
- macroName = sAutomationAgent->getMacroName(filePath).str();
+ macroName = sAutomationAgent->getMacroName(filePath);
connect(macroSavedItem,
SIGNAL(editButtonClickedSignal(RecordMacroSavedItem*)), this,
SLOT(editButtonClicked(RecordMacroSavedItem*)));