httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r603706 - /httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c
Date Wed, 12 Dec 2007 19:15:18 GMT
Author: wrowe
Date: Wed Dec 12 11:15:17 2007
New Revision: 603706

URL: http://svn.apache.org/viewvc?rev=603706&view=rev
Log:
Handle apr_sockaddr_info_get errors consistently.

Modified:
    httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c

Modified: httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c?rev=603706&r1=603705&r2=603706&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c Wed Dec 12 11:15:17 2007
@@ -1376,14 +1376,22 @@
     apr_port_t port;
     int tries = 0;
 
-    apr_sockaddr_info_get(&sa, bindaddr, bindfamily, 0, 0, c->pool);
+    rv = apr_sockaddr_info_get(&sa, bindaddr, bindfamily, 0, 0, fc->data_pool);
+
+    if (!sa || rv) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
+                      "Couldn't resolve local socket address %s (%d)"
+                      " (ftp, apr or socket stack bug?)",
+                      bindaddr, bindfamily);
+        return FTP_REPLY_CANNOT_OPEN_DATACONN;
+    }
 
 #if APR_MAJOR_VERSION < 1
     rv = apr_socket_create_ex(&s, sa->family, SOCK_STREAM,
-                              APR_PROTO_TCP, c->pool);
+                              APR_PROTO_TCP, fc->data_pool);
 #else
     rv = apr_socket_create(&s, sa->family, SOCK_STREAM,
-                           APR_PROTO_TCP, c->pool);
+                           APR_PROTO_TCP, fc->data_pool);
 #endif
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_ERR, rv, c->base_server,
@@ -1704,7 +1712,7 @@
         return FTP_REPLY_BAD_SEQUENCE;
     }
 
-    arg_tok = apr_pstrdup(c->pool, arg);
+    arg_tok = apr_pstrdup(fc->data_pool, arg);
     if ((res = ftp_eprt_decode(&family, &ip_addr, &port, arg_tok))
             != FTP_REPLY_COMMAND_OK) {
         fc->response_notes = apr_pstrdup(r->pool, "Invalid EPRT request");
@@ -1723,9 +1731,11 @@
 #endif
 
 #if APR_MAJOR_VERSION < 1
-    rv = apr_socket_create_ex(&s, family, SOCK_STREAM, APR_PROTO_TCP, c->pool);
+    rv = apr_socket_create_ex(&s, family, SOCK_STREAM, APR_PROTO_TCP,
+                              fc->data_pool);
 #else
-    rv = apr_socket_create(&s, family, SOCK_STREAM, APR_PROTO_TCP, c->pool);
+    rv = apr_socket_create(&s, family, SOCK_STREAM, APR_PROTO_TCP,
+                           fc->data_pool);
 #endif
 
     if (rv != APR_SUCCESS) {
@@ -1734,7 +1744,7 @@
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
-    sa = apr_palloc(c->pool, sizeof(apr_sockaddr_t));
+    sa = apr_palloc(fc->data_pool, sizeof(apr_sockaddr_t));
     memcpy(sa, c->local_addr, sizeof(apr_sockaddr_t));
     sa->next = NULL;
     if (sa->family == APR_INET)
@@ -1771,17 +1781,17 @@
     }
 
     rv = apr_sockaddr_info_get(&fc->clientsa, ip_addr, family,
-                               port, 0, c->pool);
-    if (rv) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, 0, c->base_server,
-                     "Unable to decode EPRT request |%d|%s|%d|",
+                               port, 0, fc->data_pool);
+    if (!fc->clientsa || rv) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, c->base_server,
+                     "Unable to resolve EPRT address of |%d|%s|%d|",
 #if APR_HAVE_IPV6
                      (family == APR_INET6) ? 2 : 1, ip_addr, port);
 #else
                      1, ip_addr, port);
 #endif
         fc->response_notes = apr_pstrdup(r->pool,
-                     "Invalid EPRT command, unable to decode request");
+                     "Invalid EPRT command, unable to resolve request");
         apr_socket_close(s);
         return FTP_REPLY_SYNTAX_ERROR;
     }
@@ -1842,7 +1852,7 @@
         return FTP_REPLY_SYNTAX_ERROR;   
     }
 
-    ip_addr = apr_psprintf(c->pool, "%d.%d.%d.%d",
+    ip_addr = apr_psprintf(fc->data_pool, "%d.%d.%d.%d",
                            val[0], val[1], val[2], val[3]);
 
     port = ((val[4] << 8) + val[5]);
@@ -1877,9 +1887,11 @@
 #endif
         
 #if APR_MAJOR_VERSION < 1
-    rv = apr_socket_create_ex(&s, APR_INET, SOCK_STREAM, APR_PROTO_TCP, c->pool);
+    rv = apr_socket_create_ex(&s, APR_INET, SOCK_STREAM, APR_PROTO_TCP,
+                              fc->data_pool);
 #else
-    rv = apr_socket_create(&s, APR_INET, SOCK_STREAM, APR_PROTO_TCP, c->pool);
+    rv = apr_socket_create(&s, APR_INET, SOCK_STREAM, APR_PROTO_TCP,
+                           fc->data_pool);
 #endif
 
     if (rv != APR_SUCCESS) {
@@ -1898,24 +1910,25 @@
     }
 
     if (c->local_addr->family == APR_INET) {
-        apr_sockaddr_info_get(&sa, c->local_ip, APR_INET,
-                              local_port, 0, c->pool);
-        if (!sa) {
+        rv = apr_sockaddr_info_get(&sa, c->local_ip, APR_INET,
+                                  local_port, 0, fc->data_pool);
+        if (!sa || rv) {
             ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
                           "Couldn't resolve explicit local socket address"
-                          " (apr or socket stack bug?)  Retrying");
-            apr_sockaddr_info_get(&sa, NULL, APR_INET,
-                                  local_port, 0, c->pool);
+                          " %s (apr or socket stack bug?)  Retrying",
+                          c->local_ip);
+            rv = apr_sockaddr_info_get(&sa, NULL, APR_INET,
+                                       local_port, 0, fc->data_pool);
         }
     }
     else {
-        apr_sockaddr_info_get(&sa, NULL, APR_INET,
-                              local_port, 0, c->pool);
+        rv = apr_sockaddr_info_get(&sa, NULL, APR_INET,
+                                   local_port, 0, fc->data_pool);
     }
 
-    if (!sa) {
+    if (!sa || rv) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
-                      "Couldn't resolve local socket address"
+                      "Couldn't resolve emphemeral local socket address"
                       " (apr or socket stack bug?)  Giving up");
         apr_socket_close(s);
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
@@ -1937,8 +1950,16 @@
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
-    apr_sockaddr_info_get(&fc->clientsa, ip_addr, APR_INET,
-                          port, 0, c->pool);
+    rv = apr_sockaddr_info_get(&fc->clientsa, ip_addr, APR_INET,
+                               port, 0, fc->datapool);
+
+    if (!fc->clientsa || rv) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
+                      "Couldn't resolve remote socket address %s"
+                      " (apr or socket stack bug?)", ip_address);
+        apr_socket_close(s);
+        return FTP_REPLY_CANNOT_OPEN_DATACONN;
+    }
 
     fc->response_notes = apr_psprintf(r->pool, FTP_MSG_SUCCESS, r->method);
     fc->csock = s;



Mime
View raw message