mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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:
10
fish/rc.c
10
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)) {
|
||||
|
||||
Reference in New Issue
Block a user