From ce78d135fc990505372e404de977a85841c49c24 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 7 Nov 2012 12:55:53 -0800 Subject: [PATCH] socket-util: Report fd of -1 on error in inet_open_active(). inet_open_active() is documented to report a fd of -1 when an error occurs. All three of its callers rely on this, by checking only the fd to determine whether there was an error. This means that if the call to set_nonblocking() or set_dscp() or connect() failed, then the callers would try to use a fd that had already been closed, wreaking havoc. This fixes a bug introduced in commit a4efa3fc5d (socket-util: Close socket on failed dscp modification.) Bug #13750. Reported-by: Scott Hendricks Signed-off-by: Ben Pfaff Acked-by: Ethan Jackson --- lib/socket-util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/socket-util.c b/lib/socket-util.c index a37dfe4a..4edf956b 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -612,6 +612,7 @@ exit: } } else if (fd >= 0) { close(fd); + fd = -1; } *fdp = fd; return error; -- 2.30.2