From 065c997f5bc18c03ccdd8566a05b274c7c060407 Mon Sep 17 00:00:00 2001 From: shivanayak Date: Tue, 10 Mar 2026 13:51:35 +0530 Subject: [PATCH] fish: fix fd leak and undefined behavior on fdopen failure in rc_listen (#320) Add missing NULL check after fdopen in both rc_listen and rc_remote. In rc_listen, fdopen failure on a valid fd indicates something fundamentally broken, so abort. In rc_remote, return an error to the caller. Co-authored-by: Claude --- fish/rc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fish/rc.c b/fish/rc.c index 056610633..0f4ca9b72 100644 --- a/fish/rc.c +++ b/fish/rc.c @@ -277,6 +277,11 @@ rc_listen (void) receive_stdout (s); fp = fdopen (s, "r+"); + if (fp == NULL) { + perror ("fdopen"); + close (s); + abort (); + } xdrstdio_create (&xdr, fp, XDR_DECODE); if (!xdr_guestfish_hello (&xdr, &hello)) { @@ -393,6 +398,11 @@ rc_remote (int pid, const char *cmd, size_t argc, char *argv[], /* Send the greeting. */ fp = fdopen (sock, "r+"); + if (fp == NULL) { + perror ("fdopen"); + close (sock); + return -1; + } xdrstdio_create (&xdr, fp, XDR_ENCODE); if (!xdr_guestfish_hello (&xdr, &hello)) {