mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00:00
fix(native): allocated getcwd and realpath results name the guest mount (#3481)
getcwd(NULL, ...) and realpath(path, NULL) returned the host path of a session mount whenever its guest path was longer than the host path, because the translation had to fit the buffer the C library allocated. Shells export that host path as PWD, and Wine prefers a valid PWD, so a program started from an added game folder on a removable card got a working directory it could not open and started in the Windows folder. Grow the allocated result to fit the guest path.
This commit is contained in:
1 parent
7404fba5a3
commit
5f129fb4db
3 files changed
+43
-5
No files matched your search
@@ -88,6 +88,18 @@ int main(int argc, char **argv) {
|
||||
printf("%s\t%s\n", argv[i], ok ? cwd : "-");
|
||||
continue;
|
||||
}
|
||||
if (strncmp(argv[i], "cdnull:", 7) == 0) {
|
||||
char *got = chdir(argv[i] + 7) == 0 ? getcwd(NULL, 0) : NULL;
|
||||
printf("%s\t%s\n", argv[i], got ? got : "-");
|
||||
free(got);
|
||||
continue;
|
||||
}
|
||||
if (strncmp(argv[i], "realnull:", 9) == 0) {
|
||||
char *got = realpath(argv[i] + 9, NULL);
|
||||
printf("%s\t%s\n", argv[i], got ? got : "-");
|
||||
free(got);
|
||||
continue;
|
||||
}
|
||||
if (strncmp(argv[i], "lstat:", 6) == 0) {
|
||||
int ok = lstat(argv[i] + 6, &st) == 0;
|
||||
printf("%s\t%d\t%d\n", argv[i], ok, ok && S_ISLNK(st.st_mode));
|
||||
@@ -324,6 +336,19 @@ class NativeHookMountTest(unittest.TestCase):
|
||||
arg = f"cd:/pfx/native/dosdevices/z:{GAME}/"
|
||||
self.assertEqual(self.run_probe(arg)[arg], [GAME])
|
||||
|
||||
def test_allocated_working_directory_and_real_path_name_a_longer_guest_mount(self):
|
||||
guest = "/root/Games/" + "g" * len(str(self.library))
|
||||
binds = f"{self.library}:{guest}"
|
||||
args = [f"cd:{guest}/Some Game", f"cdnull:{guest}/Some Game", f"realnull:{guest}/Some Game/game.txt"]
|
||||
result = self.run_probe(*args, binds=binds)
|
||||
self.assertEqual(result[args[0]], [f"{guest}/Some Game"])
|
||||
self.assertEqual(result[args[1]], [f"{guest}/Some Game"])
|
||||
self.assertEqual(result[args[2]], [f"{guest}/Some Game/game.txt"])
|
||||
|
||||
def test_allocated_working_directory_names_a_shorter_guest_mount(self):
|
||||
arg = f"cdnull:{GAME}"
|
||||
self.assertEqual(self.run_probe(arg)[arg], [GAME])
|
||||
|
||||
def test_rootfs_path_under_a_mount_point_reaches_the_mount(self):
|
||||
path = f"{self.root}{GAME}/game.txt"
|
||||
self.assertEqual(self.run_probe(path)[path], ["1", "library"])
|
||||
|
||||
Reference in new issue
Block a user