From db9ae836729c31df13eff3d0b31acc7cc908a176 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 26 Oct 2026 06:42:01 +0530 Subject: [PATCH] macOS: Verify that the pty name from ptsname_r() matches the slave fd Since the pty name is now obtained from the master fd, check that it refers to the same device as the slave fd, so that a mismatched pair passed to spawn() raises an error instead of silently giving the child the wrong controlling terminal. Also merge the changelog entry into the existing macOS bullet. --- docs/changelog.rst | 9 ++++----- kitty/child.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 897183902..cdeeec1ae 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -436,11 +436,10 @@ Detailed list of changes :pull:`10721`) - macOS: Fix padding rendering black after sleep, OS windows not staying on all - spaces, a duplicate path when dropping items from Apple Mail and a memory - leak (:iss:`10708`, :iss:`10581`, :iss:`10628`, :iss:`10673`) - -- macOS: Fix kitty freezing when opening a new window while another entry in - :file:`/dev` is stuck (:iss:`10741`) + spaces, a duplicate path when dropping items from Apple Mail, a memory + leak and kitty freezing when opening a new window while another entry in + :file:`/dev` is stuck (:iss:`10708`, :iss:`10581`, :iss:`10628`, + :iss:`10673`, :iss:`10741`) 0.49.2 [2026-10-01] diff --git a/kitty/child.c b/kitty/child.c index 77b6f89dc..88f423002 100644 --- a/kitty/child.c +++ b/kitty/child.c @@ -120,6 +120,22 @@ spawn(PyObject *self UNUSED, PyObject *args) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } +#ifdef __APPLE__ + // The name came from master, ensure it refers to the same pty as slave + struct stat slave_st, name_st; + if (fstat(slave, &slave_st) != 0) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + if (stat(name, &name_st) != 0) { + PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); + return NULL; + } + if (slave_st.st_rdev != name_st.st_rdev) { + PyErr_Format(PyExc_ValueError, "The slave fd %d is not the pty of the master fd %d (%s)", slave, master, name); + return NULL; + } +#endif char **argv = serialize_string_tuple(argv_p, 0); if (!argv) return NULL; char **env = serialize_string_tuple(env_p, 1);