diff --git a/tools/nativeguest/hook/exec.c b/tools/nativeguest/hook/exec.c index 8d18c2d394..b4249eb06c 100644 --- a/tools/nativeguest/hook/exec.c +++ b/tools/nativeguest/hook/exec.c @@ -54,12 +54,11 @@ static void resolve_symlinks(const char *path, char *out, size_t out_size, int d if (used >= sizeof(done) - 1) return; if (!follow_link(done, link_target, sizeof(link_target))) { struct stat st; - if (rest[strspn(rest, "/")] && (syscall(SYS_newfstatat, AT_FDCWD, done, &st, 0) != 0 || !S_ISDIR(st.st_mode))) return; + if (*rest && (syscall(SYS_newfstatat, AT_FDCWD, done, &st, 0) != 0 || !S_ISDIR(st.st_mode))) return; continue; } if (++links > 40) return; size_t m = ddnatv_append(next_path, sizeof(next_path), 0, link_target, strlen(link_target)); - m = ddnatv_append(next_path, sizeof(next_path), m, "/", 1); m = ddnatv_append(next_path, sizeof(next_path), m, rest, strlen(rest)); if (m >= sizeof(next_path) - 1) return; if (link_target[0] == '/') { diff --git a/tools/tests/test_native_hook_exec_target.py b/tools/tests/test_native_hook_exec_target.py index 29c7b10cac..9cc0550cac 100644 --- a/tools/tests/test_native_hook_exec_target.py +++ b/tools/tests/test_native_hook_exec_target.py @@ -108,6 +108,12 @@ class NativeHookExecTargetTest(unittest.TestCase): def test_a_file_is_not_used_as_a_directory(self): self.assertNotEqual(self.real, self.exe("/opt/real/prog/../prog")) + def test_a_trailing_slash_after_a_program_is_not_dropped(self): + self.assertNotEqual(self.real, self.exe("/opt/real/prog/")) + + def test_a_trailing_slash_after_a_link_to_a_program_is_not_dropped(self): + self.assertNotEqual(self.real, self.exe("/opt/link/")) + def test_a_proot_hard_link_keeps_its_own_name(self): self.assertEqual(str(self.root / "opt/real/hard"), self.exe("/opt/real/hard"))