Make the log message in setInteractive a local variable.
If the error message isn't a local variable, it will go out of scope
immediately after LogIfSlow is constructed. Unfortunately, LogIfSlow
maintains a pointer to String8s internal char* member... which causes a
use after free when it goes to log. Oops.
Bug: 62820330
Test: none
Change-Id: Ie1da3be723f8aae165822002ff42954480a43aa5
diff --git a/services/core/jni/com_android_server_power_PowerManagerService.cpp b/services/core/jni/com_android_server_power_PowerManagerService.cpp
index c722629..86c5e99 100644
--- a/services/core/jni/com_android_server_power_PowerManagerService.cpp
+++ b/services/core/jni/com_android_server_power_PowerManagerService.cpp
@@ -157,8 +157,10 @@
static void nativeSetInteractive(JNIEnv* /* env */, jclass /* clazz */, jboolean enable) {
std::lock_guard<std::mutex> lock(gPowerHalMutex);
if (getPowerHal()) {
- String8 err("Excessive delay in setInteractive(%s) while turning screen %s");
- ALOGD_IF_SLOW(20, String8::format(err, enable ? "true" : "false", enable ? "on" : "off"));
+ String8 err = String8::format(
+ "Excessive delay in setInteractive(%s) while turning screen %s",
+ enable ? "true" : "false", enable ? "on" : "off");
+ ALOGD_IF_SLOW(20, err);
Return<void> ret = gPowerHal->setInteractive(enable);
processReturn(ret, "setInteractive");
}