fix(nativeguest): preserve empty caller library path components

This commit is contained in:
maxjivi05 committed 2026-11-24 10:20:25 -05:00
1 parent f0fd86e3ee
commit 5b67428b27
2 files changed
+17 -1

No files matched your search

@@ -271,7 +271,7 @@ object NativeGuest {
fun builder(root: File, cwd: String, argv: List<String>, env: Map<String, String>, preload: List<String> = 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)
@@ -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()