fa34f0
--- a/modules/proxy/mod_proxy_ftp.c	2020/02/07 17:01:07	1873744
fa34f0
+++ b/modules/proxy/mod_proxy_ftp.c	2020/02/07 17:04:45	1873745
fa34f0
@@ -218,7 +218,7 @@
fa34f0
  * (EBCDIC) machines either.
fa34f0
  */
fa34f0
 static apr_status_t ftp_string_read(conn_rec *c, apr_bucket_brigade *bb,
fa34f0
-        char *buff, apr_size_t bufflen, int *eos)
fa34f0
+        char *buff, apr_size_t bufflen, int *eos, apr_size_t *outlen)
fa34f0
 {
fa34f0
     apr_bucket *e;
fa34f0
     apr_status_t rv;
fa34f0
@@ -230,6 +230,7 @@
fa34f0
     /* start with an empty string */
fa34f0
     buff[0] = 0;
fa34f0
     *eos = 0;
fa34f0
+    *outlen = 0;
fa34f0
 
fa34f0
     /* loop through each brigade */
fa34f0
     while (!found) {
fa34f0
@@ -273,6 +274,7 @@
fa34f0
                 if (len > 0) {
fa34f0
                     memcpy(pos, response, len);
fa34f0
                     pos += len;
fa34f0
+                    *outlen += len;
fa34f0
                 }
fa34f0
             }
fa34f0
             apr_bucket_delete(e);
fa34f0
@@ -385,28 +387,36 @@
fa34f0
     char buff[5];
fa34f0
     char *mb = msgbuf, *me = &msgbuf[msglen];
fa34f0
     apr_status_t rv;
fa34f0
+    apr_size_t nread;
fa34f0
+    
fa34f0
     int eos;
fa34f0
 
fa34f0
-    if (APR_SUCCESS != (rv = ftp_string_read(ftp_ctrl, bb, response, sizeof(response), &eos))) {
fa34f0
+    if (APR_SUCCESS != (rv = ftp_string_read(ftp_ctrl, bb, response, sizeof(response), &eos, &nread))) {
fa34f0
         return -1;
fa34f0
     }
fa34f0
 /*
fa34f0
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL, APLOGNO(03233)
fa34f0
                  "<%s", response);
fa34f0
 */
fa34f0
+    if (nread < 4) { 
fa34f0
+        ap_log_error(APLOG_MARK, APLOG_INFO, 0, NULL, APLOGNO(10229) "Malformed FTP response '%s'", response);
fa34f0
+        *mb = '\0';
fa34f0
+        return -1;
fa34f0
+    }
fa34f0
+
fa34f0
     if (!apr_isdigit(response[0]) || !apr_isdigit(response[1]) ||
fa34f0
-    !apr_isdigit(response[2]) || (response[3] != ' ' && response[3] != '-'))
fa34f0
+        !apr_isdigit(response[2]) || (response[3] != ' ' && response[3] != '-'))
fa34f0
         status = 0;
fa34f0
     else
fa34f0
         status = 100 * response[0] + 10 * response[1] + response[2] - 111 * '0';
fa34f0
 
fa34f0
     mb = apr_cpystrn(mb, response + 4, me - mb);
fa34f0
 
fa34f0
-    if (response[3] == '-') {
fa34f0
+    if (response[3] == '-') { /* multi-line reply "123-foo\nbar\n123 baz" */
fa34f0
         memcpy(buff, response, 3);
fa34f0
         buff[3] = ' ';
fa34f0
         do {
fa34f0
-            if (APR_SUCCESS != (rv = ftp_string_read(ftp_ctrl, bb, response, sizeof(response), &eos))) {
fa34f0
+            if (APR_SUCCESS != (rv = ftp_string_read(ftp_ctrl, bb, response, sizeof(response), &eos, &nread))) {
fa34f0
                 return -1;
fa34f0
             }
fa34f0
             mb = apr_cpystrn(mb, response + (' ' == response[0] ? 1 : 4), me - mb);