From 798f6e87b3ca7f88f17c32d011f7b1292134b5ff Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 7 May 2022 12:31:14 +0300 Subject: [PATCH] (ftpfs_initconn): clarify errno setup. Handle errors of bind(), getsockname(), and listen() calls. Return if one of these functions fails and setup errno to indicate the cause of the error. Signed-off-by: Andrew Borodin --- src/vfs/ftpfs/ftpfs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index d3fa5a636..c7514140b 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -1403,10 +1403,15 @@ ftpfs_initconn (struct vfs_class *me, struct vfs_s_super *super) if (data_sock < 0) return (-1); - if ((bind (data_sock, (struct sockaddr *) &data_addr, data_addrlen) == 0) && - (getsockname (data_sock, (struct sockaddr *) &data_addr, &data_addrlen) == 0) && - (listen (data_sock, 1) == 0) && - (ftpfs_setup_active (me, super, data_addr, data_addrlen) != 0)) + if ((bind (data_sock, (struct sockaddr *) &data_addr, data_addrlen) != 0) || + (getsockname (data_sock, (struct sockaddr *) &data_addr, &data_addrlen) != 0) || + (listen (data_sock, 1) != 0)) + { + close (data_sock); + ERRNOR (errno, -1); + } + + if (ftpfs_setup_active (me, super, data_addr, data_addrlen) != 0) return data_sock; close (data_sock);