Skip to content

Commit

Permalink
Merge pull request #253 from Castaglia/ftp-interop-feat-blank-lines
Browse files Browse the repository at this point in the history
Issue #251: Handle an interoperability edge case, where some specific…
  • Loading branch information
Castaglia committed Jul 23, 2023
2 parents ca6650e + 322e00d commit 5d35be6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 4 additions & 2 deletions include/proxy/ftp/ctrl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ProFTPD - mod_proxy FTP control conn API
* Copyright (c) 2012-2020 TJ Saunders
* Copyright (c) 2012-2023 TJ Saunders
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -28,7 +28,9 @@
#include "mod_proxy.h"

/* Note: this flag is only used for testing. */
#define PROXY_FTP_CTRL_FL_IGNORE_EOF 0x0001
#define PROXY_FTP_CTRL_FL_IGNORE_EOF 0x0001

#define PROXY_FTP_CTRL_FL_IGNORE_BLANK_RESP 0x0002

int proxy_ftp_ctrl_handle_async(pool *p, conn_t *backend_conn,
conn_t *frontend_conn, int flags);
Expand Down
7 changes: 7 additions & 0 deletions lib/proxy/ftp/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ pr_response_t *proxy_ftp_ctrl_recv_resp(pool *p, conn_t *ctrl_conn,
buflen--;
}

if (buflen == 0 &&
(flags & PROXY_FTP_CTRL_FL_IGNORE_BLANK_RESP)) {
pr_trace_msg(trace_channel, 19, "%s",
"skipping blank response line from backend server");
continue;
}

/* If we are the first line of the response, the first three characters
* MUST be numeric, followed by a hypen. Anything else is nonconformant
* with RFC 959.
Expand Down
14 changes: 11 additions & 3 deletions lib/proxy/ftp/sess.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ProFTPD - mod_proxy FTP session routines
* Copyright (c) 2013-2022 TJ Saunders
* Copyright (c) 2013-2023 TJ Saunders
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -100,7 +100,7 @@ static int parse_feat(pool *p, const char *feat, array_header **res) {

int proxy_ftp_sess_get_feat(pool *p, const struct proxy_session *proxy_sess) {
pool *tmp_pool;
int res, xerrno = 0;
int flags, res, xerrno = 0;
cmd_rec *cmd;
pr_response_t *resp;
unsigned int resp_nlines = 0;
Expand Down Expand Up @@ -129,8 +129,16 @@ int proxy_ftp_sess_get_feat(pool *p, const struct proxy_session *proxy_sess) {
return -1;
}

/* Some broken FTP servers actually send blank lines in responses, such
* as in a FEAT response. Ugh. (See Issue #251.)
*
* TODO: Should this use some sort of "enable compatibility with broken/
* non-conformat servrs" ProxyOption/flag?
*/
flags = PROXY_FTP_CTRL_FL_IGNORE_BLANK_RESP;

resp = proxy_ftp_ctrl_recv_resp(tmp_pool, proxy_sess->backend_ctrl_conn,
&resp_nlines, 0);
&resp_nlines, flags);
if (resp == NULL) {
xerrno = errno;

Expand Down

0 comments on commit 5d35be6

Please sign in to comment.