From b92fd90719dd01f2fccd5347e2365dafa5af4da0 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Thu, 14 Nov 1996 05:05:26 +0000 Subject: [PATCH] 1) Don't allow endless recursion in ftp_close when it attempts to send QUIT to closed connection. 2) Preserve login failure code, don't overwrite it with ftp_close code Should go to 2.2 --- lib/libftpio/ftpio.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/libftpio/ftpio.c b/lib/libftpio/ftpio.c index 578d5b7c2c11..1fe853747554 100644 --- a/lib/libftpio/ftpio.c +++ b/lib/libftpio/ftpio.c @@ -14,7 +14,7 @@ * Turned inside out. Now returns xfers as new file ids, not as a special * `state' of FTP_t * - * $Id: ftpio.c,v 1.14 1996/09/19 17:28:26 peter Exp $ + * $Id: ftpio.c,v 1.15 1996/10/10 08:34:27 jkh Exp $ * */ @@ -540,17 +540,21 @@ static int ftp_close(FTP_t ftp) { int i; + static int recursive = 0; - if (ftp->con_state == isopen) { + if (!recursive && ftp->con_state == isopen) { /* Debug("ftp_pkg: in ftp_close(), sending QUIT"); */ + recursive = 1; i = cmd(ftp, "QUIT"); close(ftp->fd_ctrl); ftp->fd_ctrl = -1; ftp->con_state = init; if (check_code(ftp, i, FTP_QUIT_HAPPY)) { + recursive = 0; ftp->errno = i; return FAILURE; } + recursive = 0; /* Debug("ftp_pkg: ftp_close() - proper shutdown"); */ return SUCCESS; } @@ -647,6 +651,8 @@ ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port, int i = cmd(ftp, "PASS %s", passwd); if (i >= 299 || i < 0) { ftp_close(ftp); + if (i > 0) + ftp->errno = i; return FAILURE; } return SUCCESS;