From 6e04acf9ed089f065b19ff4e42be97bd17529ff2 Mon Sep 17 00:00:00 2001 From: "Ned T. Crigler" Date: Thu, 19 Jun 2025 11:22:55 -0700 Subject: Check the return value of the fchdir() system call dtach was not checking if the fchdir back to the old directory worked when it tried to get around the sun_path length limit. --- attach.c | 12 ++++++++++-- master.c | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/attach.c b/attach.c index 5fd301c..8ac3bf3 100644 --- a/attach.c +++ b/attach.c @@ -170,7 +170,11 @@ attach_main(int noerror) if (chdir(sockname) >= 0) { s = connect_socket(slash + 1); - fchdir(dirfd); + if (s >= 0 && fchdir(dirfd) < 0) + { + close(s); + s = -1; + } } *slash = '/'; close(dirfd); @@ -315,7 +319,11 @@ push_main() if (chdir(sockname) >= 0) { s = connect_socket(slash + 1); - fchdir(dirfd); + if (s >= 0 && fchdir(dirfd) < 0) + { + close(s); + s = -1; + } } *slash = '/'; close(dirfd); diff --git a/master.c b/master.c index 3755f65..81aa6a9 100644 --- a/master.c +++ b/master.c @@ -594,7 +594,11 @@ master_main(char **argv, int waitattach, int dontfork) if (chdir(sockname) >= 0) { s = create_socket(slash + 1); - fchdir(dirfd); + if (s >= 0 && fchdir(dirfd) < 0) + { + close(s); + s = -1; + } } *slash = '/'; close(dirfd); -- cgit v1.2.3