This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository terminology.
View the commit online.
commit 48bab8abe391dbb2b119c0a3a107d95c5d9cc5a1
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 13:07:16 2026 -0600
tymuxd: delete a client's fd handler before closing its socket
When a client hung up, its read callback cleared client->handler and
returned ECORE_CALLBACK_CANCEL: the socket was closed while ecore still
had the fd on its epoll set. Ecore could not take it off, and the EBADF
made it rebuild its whole main loop. Two such rebuilds before the next
select can leave a freed handler on ecore's list of prepare callbacks,
which the daemon then reads: a crash when freed memory gets overwritten.
Delete the handler before closing the socket, as _client_free() already
does. The test has twenty clients hang up in the same loop iteration,
with freed memory filled by glibc and ecore freeing its handlers at
once.
---
src/bin/termd_tymux.c | 9 +++++++--
tests/tymux.py | 29 +++++++++++++++++++++++++++--
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/src/bin/termd_tymux.c b/src/bin/termd_tymux.c
index 20e560ee..e2d093b0 100644
--- a/src/bin/termd_tymux.c
+++ b/src/bin/termd_tymux.c
@@ -360,9 +360,14 @@ _cb_client_data(void *data, Ecore_Fd_Handler *fd_handler)
if (!client->dead)
return ECORE_CALLBACK_RENEW;
- client->handler = NULL;
+ /* _client_free() deletes the handler before it closes the socket.
+ * Leaving that to ECORE_CALLBACK_CANCEL would make ecore remove a closed
+ * fd from its epoll set: the EBADF makes it rebuild its whole loop, and
+ * two rebuilds in one iteration leave a freed handler in its list of
+ * prepare callbacks. What a handler that deleted itself returns is
+ * ignored. */
_client_free(client);
- return ECORE_CALLBACK_CANCEL;
+ return ECORE_CALLBACK_RENEW;
}
static void
diff --git a/tests/tymux.py b/tests/tymux.py
index 0974ff6a..7d6f26db 100644
--- a/tests/tymux.py
+++ b/tests/tymux.py
@@ -112,10 +112,10 @@ def check(cond, what):
class Client:
"""tymux running in a pseudo terminal of rows x cols"""
- def __init__(self, args, rows=24, cols=80):
+ def __init__(self, args, rows=24, cols=80, env=ENV):
self.pid, self.fd = pty.fork()
if self.pid == 0:
- os.execve(TYMUX, [TYMUX] + args, ENV)
+ os.execve(TYMUX, [TYMUX] + args, env)
self.resize(rows, cols)
self.out = b""
self.status = None
@@ -348,6 +348,31 @@ def main():
a.send("exit\r")
check(a.wait() == 0, "exit after the stuck client test")
+ # clients hanging up together are seen by tymuxd in one loop iteration.
+ # Reading a freed ecore fd handler only crashes once the memory is
+ # overwritten: have glibc fill freed memory, and have ecore free its
+ # handlers at once rather than keep them in a pool. Without the pool,
+ # LeakSanitizer reports the handlers ecore still holds at exit.
+ name = NAME + "g"
+ env = dict(ENV, MALLOC_PERTURB_="4", EINA_MEMPOOL_PASS="1",
+ LSAN_OPTIONS="detect_leaks=0")
+ a = Client(["new", name], env=env)
+ check(a.expect("$ "), "new for the hanging up clients test")
+ path = os.path.join(XDG, "terminology", "tymux", name + ".sock")
+ hangups = []
+ for _ in range(20):
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ sock.connect(path)
+ hangups.append(sock)
+ time.sleep(0.5)
+ for sock in hangups:
+ sock.close()
+ a.idle(1)
+ a.send("echo hangup-$((9+9))\r")
+ check(a.expect("hangup-18"), "tymuxd serves its client once others hang up")
+ a.send("exit\r")
+ check(a.wait() == 0, "exit after the hanging up clients test")
+
result = tymux("attach", NAME)
check(result.returncode == 1 and "no tymux" in result.stderr,
"attach to a missing tymux fails")
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.