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 <nor@anthropic.com>
This commit is contained in:
shivanayak
2026-03-10 13:51:35 +05:30
committed by GitHub
parent 2fc54b8121
commit 065c997f5b

View File

@@ -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)) {