Skip to content

Commit 51adca0

Browse files
committed
Only chdir to / if the cwd is not executable or does not exist. Fixes #8636
1 parent 123a115 commit 51adca0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

kitty/child.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ spawn(PyObject *self UNUSED, PyObject *args) {
106106
sigset_t signals; sigemptyset(&signals);
107107
if (sigprocmask(SIG_SETMASK, &signals, NULL) != 0) exit_on_err("sigprocmask() in child process failed");
108108
// Use only signal-safe functions (man 7 signal-safety)
109-
if (chdir(cwd) != 0) { if (chdir("/") != 0) {} }; // ignore failure to chdir to /
109+
if (chdir(cwd) != 0) {
110+
if (access(".", X_OK) != 0) { // existing cwd does not exist or dont have permissions for it
111+
if (chdir("/") != 0) {} // ignore failure to chdir to /
112+
}
113+
};
110114
if (setsid() == -1) exit_on_err("setsid() in child process failed");
111115

112116
// Establish the controlling terminal (see man 7 credentials)

0 commit comments

Comments
 (0)