From 5b67428b275441bea81b0aaa5911ab4758a94baa Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Tue, 24 Nov 2026 10:20:25 -0500 Subject: [PATCH] fix(nativeguest): preserve empty caller library path components --- .../droiddeck/launcher/runtime/NativeGuest.kt | 2 +- .../launcher/runtime/NativeGuestTest.kt | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt b/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt index 3aed3bfeec..c609fe7c4b 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt @@ -271,7 +271,7 @@ object NativeGuest { fun builder(root: File, cwd: String, argv: List, env: Map, preload: List = emptyList()): ProcessBuilder { val program = argv.first() - val callerDirs = env["LD_LIBRARY_PATH"]?.split(':')?.filter { it.isNotEmpty() }.orEmpty() + val callerDirs = env["LD_LIBRARY_PATH"]?.takeIf { it.isNotEmpty() }?.split(':').orEmpty() val rootDirs = libraryPath(root).split(':').filterNot { it in callerDirs } val cmd = command(root, program, argv.drop(1), (callerDirs + rootDirs).joinToString(":")) val builder = ProcessBuilder(cmd).redirectErrorStream(false) diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt index 0480b723c3..4fe7a60dc0 100644 --- a/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt @@ -60,6 +60,22 @@ class NativeGuestTest { assertEquals(callerPath, builder.environment()["LD_LIBRARY_PATH"]) } + @Test + fun builderPreservesEmptyCallerLibraryPathComponents() { + val root = rootWithLoader() + val rootPath = NativeGuest.libraryPath(root) + for (callerPath in listOf(":/custom/lib", "/custom/lib:", ":/custom/lib::")) { + val builder = NativeGuest.builder(root, "/", listOf("/usr/bin/env"), mapOf("LD_LIBRARY_PATH" to callerPath)) + val command = builder.command() + assertEquals("$callerPath:$rootPath", command[command.indexOf("--library-path") + 1]) + assertEquals(callerPath, builder.environment()["LD_LIBRARY_PATH"]) + } + for (env in listOf(emptyMap(), mapOf("LD_LIBRARY_PATH" to ""))) { + val command = NativeGuest.builder(root, "/", listOf("/usr/bin/env"), env).command() + assertEquals(rootPath, command[command.indexOf("--library-path") + 1]) + } + } + @Test fun mountsWithoutADestinationMapToThemselves() { val root = rootWithLoader()