[Scummvm-git-logs] scummvm master -> 3a57523490f9c0aa9f4dad555d8d9ded8097c080

lephilousophe noreply at scummvm.org
Sat Jun 22 18:24:05 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
3a57523490 ANDROID: Avoid use-after-free when setting up touch mode


Commit: 3a57523490f9c0aa9f4dad555d8d9ded8097c080
    https://github.com/scummvm/scummvm/commit/3a57523490f9c0aa9f4dad555d8d9ded8097c080
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-06-22T20:23:49+02:00

Commit Message:
ANDROID: Avoid use-after-free when setting up touch mode

We set up touch mode in graphics managers constructor.
At this point, the _graphicsManager variable was pointed to the freshly
deleted old manager instead of being null.
When we are in this position, assume the cursor is at top left.

Changed paths:
    backends/platform/android/android.cpp
    backends/platform/android/events.cpp


diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 8aee751d060..a1ccd4f49d5 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -970,6 +970,7 @@ bool OSystem_Android::setGraphicsMode(int mode, uint flags) {
 	if (render3d && !supports3D) {
 		debug(5, "switching to 3D graphics");
 		delete _graphicsManager;
+		_graphicsManager = nullptr;
 		AndroidGraphics3dManager *manager = new AndroidGraphics3dManager();
 		_graphicsManager = manager;
 		androidGraphicsManager = manager;
@@ -977,6 +978,7 @@ bool OSystem_Android::setGraphicsMode(int mode, uint flags) {
 	} else if (!render3d && supports3D) {
 		debug(5, "switching to 2D graphics");
 		delete _graphicsManager;
+		_graphicsManager = nullptr;
 		AndroidGraphicsManager *manager = new AndroidGraphicsManager();
 		_graphicsManager = manager;
 		androidGraphicsManager = manager;
diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index ddf93a1334c..4918b331d1e 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -1541,7 +1541,12 @@ void OSystem_Android::setupTouchMode(int oldValue, int newValue) {
 
 	if (newValue == TOUCH_MODE_TOUCHPAD) {
 		// Make sure we have a proper touch point if we switch to touchpad mode with finger down
-		_touch_pt_down = dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->getMousePosition();
+		if (_graphicsManager) {
+			_touch_pt_down = dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->getMousePosition();
+		} else {
+			_touch_pt_down.x = 0;
+			_touch_pt_down.y = 0;
+		}
 		_touch_pt_scroll.x = -1;
 		_touch_pt_scroll.y = -1;
 	}




More information about the Scummvm-git-logs mailing list