From 0b8d55d434f416d9d3ce51daee787f75cb6b135e Mon Sep 17 00:00:00 2001 From: angelrenefm <17342133+angelrenefm@users.noreply.github.com> Date: Fri, 16 Oct 2026 14:05:02 +0000 Subject: [PATCH] fix: droiddeckctl refuses a DROIDDECK_PACKAGE that is not a package name (#896) The value goes to the device shell inside `am start -n` and `content call --uri`. Anything but a dotted Android package name is refused before adb runs. --- tools/droiddeckctl | 3 +++ tools/tests/test_droiddeckctl.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/tools/droiddeckctl b/tools/droiddeckctl index e7a31c27d5..65e0e74459 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -26,6 +26,7 @@ from adb_device import DeviceResolutionError, resolve_serial # tools/release/variants.txt: the same app also ships as other packages (e.g. com.antutu.benchmark.full). PACKAGE = os.environ.get("DROIDDECK_PACKAGE", "com.droiddeck.launcher") AUTHORITY = f"content://{PACKAGE}.agent" +PACKAGE_NAME = re.compile(r"[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)+") STEAM_CLIENT_APP = 769 REQUEST_CAP = 256 * 1024 @@ -886,6 +887,8 @@ def main(argv: list[str] | None = None) -> int: args = build_parser().parse_args(argv) serial = None try: + if not PACKAGE_NAME.fullmatch(PACKAGE): # it reaches the device shell through `am start` and `content call` + raise ControlError(f"DROIDDECK_PACKAGE is not an Android package name: {PACKAGE!r}", "INVALID_REQUEST") adb = adb_path(args.adb) serial = resolve_serial(adb, args.serial, log=True) result = execute(args, adb, serial) diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 2b0a554a6c..f6d29030a5 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -160,6 +160,16 @@ class DroiddeckctlTest(FakeAdbTest): started = [e["args"] for e in self.calls() if e["args"][:3] == ["shell", "am", "start"]] self.assertIn("com.antutu.benchmark.full/com.droiddeck.launcher.agent.AgentStartActivity", started[0]) + def test_a_malformed_package_is_refused_before_adb(self): + with unittest.mock.patch.dict(os.environ, {"DROIDDECK_PACKAGE": "com.example;reboot"}): + variant = load("droiddeckctl") + out = io.StringIO() + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(io.StringIO()): + code = variant.main(["--adb", str(self.adb), "--serial", "fake-1", "state"]) + self.assertEqual(2, code) + self.assertEqual("INVALID_REQUEST", json.loads(out.getvalue())["error"]["code"]) + self.assertFalse(self.calls()) + def test_state_passes_through_with_the_serial(self): self.configure({"state": state()}) code, out = self.run_ctl("state")