httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r604093 - in /httpd/mod_ftp/trunk: include/mod_ftp.h modules/ftp/ftp_commands.c modules/ftp/ftp_connection.c
Date Fri, 14 Dec 2007 03:40:53 GMT
Author: wrowe
Date: Thu Dec 13 19:40:50 2007
New Revision: 604093

URL: http://svn.apache.org/viewvc?rev=604093&view=rev
Log:
convert ->cwd and ->rename_from elements from pointers greedly
allocated from the connection pool into fixed APR_PATH_MAX+1 string
buffers for the life of the connection, avoid incrementally eating memory.

Modified:
    httpd/mod_ftp/trunk/include/mod_ftp.h
    httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c
    httpd/mod_ftp/trunk/modules/ftp/ftp_connection.c

Modified: httpd/mod_ftp/trunk/include/mod_ftp.h
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/include/mod_ftp.h?rev=604093&r1=604092&r2=604093&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/include/mod_ftp.h (original)
+++ httpd/mod_ftp/trunk/include/mod_ftp.h Thu Dec 13 19:40:50 2007
@@ -294,8 +294,8 @@
     apr_off_t traffic;        /* Total data channel traffic, plus HELP */
 
     /* Command state */
-    const char *cwd;          /* Directory information */
-    const char *rename_from;  /* Storage for the RNFR command.  */
+    char *cwd;                /* APR_PATH_MAX+1 buffer for Current Directory */
+    char *rename_from;        /* APR_PATH_MAX+1 buffer for the RNFR command */
     int type;                 /* FTP transmission (TYPE_A/TYPE_I) */
     apr_off_t restart_point;  /* For data transfers */
     int filter_mask;          /* Filters required (CRLF, BYTERANGE, etc) */

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=604093&r1=604092&r2=604093&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c Thu Dec 13 19:40:50 2007
@@ -322,7 +322,7 @@
 
     /* Handle special case where the URI is / */
     if (r->uri[0] == '/' && !r->uri[1]) {
-        fc->cwd = apr_pstrdup(c->pool, r->uri);
+        apr_cpystrn(fc->cwd, r->uri, APR_PATH_MAX + 1);
          
         if (dconf->readme) {
 
@@ -371,7 +371,7 @@
             response = FTP_REPLY_FILE_NOT_FOUND;
         }
         else {
-            fc->cwd = apr_pstrdup(c->pool, r->parsed_uri.path);
+            apr_cpystrn(fc->cwd, r->parsed_uri.path, APR_PATH_MAX + 1);
             
             if (dconf->readme) {
                 /* We do not inherit readme messages.  If this readme was
@@ -1016,6 +1016,7 @@
     char *userpass;
     server_rec *ftpserver;
     apr_status_t rv;
+    char *tmppath;
 
     ftp_server_config *fsc = 
         ftp_get_module_config(c->base_server->module_config);
@@ -1024,7 +1025,7 @@
      * with each attempt to finish logging in.
      */
     c->base_server = fc->orig_server;
-    fc->cwd        = "/";
+    apr_cpystrn(fc->cwd, "/", APR_PATH_MAX + 1);
 
     /* By this point we have already extracted the arguments, so rewrite
      * the original request to not include the password */
@@ -1091,7 +1092,6 @@
 
     if (fsc->docrootenv) {
         const char *docroot;
-        char *newroot;
 
         /* Invoke a request that forces auth to occur,
          * Then check for an fsc->docrootenv that translates 
@@ -1107,11 +1107,11 @@
                           "was empty or not found, using default DocumentRoot",
                           fsc->docrootenv);
         }
-        else if (((rv = apr_filepath_merge(&newroot, NULL, docroot, 
+        else if (((rv = apr_filepath_merge(&tmppath, NULL, docroot, 
                                          APR_FILEPATH_TRUENAME 
                                        | APR_FILEPATH_NOTRELATIVE, 
                                          c->pool)) != APR_SUCCESS)
-              || (rv = APR_ENOTDIR, !ap_is_directory(r->pool, newroot))) {
+              || (rv = APR_ENOTDIR, !ap_is_directory(r->pool, tmppath))) {
             ap_log_perror(APLOG_MARK, APLOG_WARNING, rv,
                           r->pool,
                           "Warning: Document Root [%s] from FTPDocRootEnv [%s] "
@@ -1119,7 +1119,7 @@
                           docroot, fsc->docrootenv);
         }
         else {
-            ftpcore->ap_document_root = newroot;
+            ftpcore->ap_document_root = tmppath;
         }
 
         ap_destroy_sub_req(rr);
@@ -1137,8 +1137,8 @@
             if (rr->finfo.filetype == APR_DIR &&
                 (rr->status == HTTP_OK ||
                  rr->status == HTTP_MOVED_PERMANENTLY)) {
-
-                fc->cwd = apr_pstrcat(c->pool, userdir, "/", NULL);
+                tmppath = apr_pstrcat(r->pool, userdir, "/", NULL);
+                apr_cpystrn(fc->cwd, tmppath, APR_PATH_MAX + 1);
             }
             else if (rr->status == HTTP_OK &&
                      rr->finfo.filetype == APR_NOFILE) {
@@ -1162,7 +1162,8 @@
                         }
                         else {
                             /* The new directory was created. */
-                            fc->cwd = apr_pstrcat(c->pool, userdir, "/", NULL);
+                            tmppath = apr_pstrcat(r->pool, userdir, "/", NULL);
+                            apr_cpystrn(fc->cwd, tmppath, APR_PATH_MAX + 1);
                             ap_log_error(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO,
                                          0, c->base_server, "Created home "
                                          "directory (%s) for user %s",
@@ -1204,7 +1205,7 @@
         }
         ftpcore->ap_document_root = apr_pstrcat(c->pool, 
                   ftpcore->ap_document_root, userdir, NULL);
-        fc->cwd = apr_pstrdup(c->pool, "/");
+        apr_cpystrn(fc->cwd, "/", APR_PATH_MAX + 1);
     }
 
     /* Our document_root and cwd are now constructed for the user... */
@@ -2219,7 +2220,6 @@
 {
     ftp_connection *fc = ftp_get_module_config(r->request_config);
     request_rec *rr;
-    conn_rec *c = r->connection;
     apr_status_t res;
     int response;
 
@@ -2237,7 +2237,7 @@
     else if (rr->finfo.filetype != APR_NOFILE) {
         fc->response_notes = apr_pstrdup(r->pool, "File exists, ready for "
                                          "destination name");
-        fc->rename_from = apr_pstrdup(c->pool, r->filename);
+        apr_cpystrn(fc->rename_from, r->filename, APR_PATH_MAX + 1);
         response = FTP_REPLY_PENDING;
     }
     else {
@@ -2259,7 +2259,7 @@
     request_rec *rr;
     
     if ((res = ftp_set_uri(r, arg))) {
-        fc->rename_from = NULL;
+        fc->rename_from[0] = '\0';
         return res;
     }
 
@@ -2275,7 +2275,7 @@
     ap_destroy_sub_req(rr);
 
     /* RNTO *must* be preceeded by RNFR */
-    if (fc->rename_from == NULL) {
+    if (fc->rename_from[0] == '\0') {
         return FTP_REPLY_BAD_SEQUENCE;
     }
     
@@ -2288,7 +2288,7 @@
         response = FTP_REPLY_COMPLETED;
     }
 
-    fc->rename_from = NULL;
+    fc->rename_from[0] = '\0';
     return response;
 }
 

Modified: httpd/mod_ftp/trunk/modules/ftp/ftp_connection.c
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/modules/ftp/ftp_connection.c?rev=604093&r1=604092&r2=604093&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_connection.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_connection.c Thu Dec 13 19:40:50 2007
@@ -41,10 +41,16 @@
     fc->user             = "unknown";
     fc->auth             = FTP_AUTH_NONE;
     fc->prot             = FTP_PROT_CLEAR;
-    fc->cwd              = "/";
     fc->type             = TYPE_A;
     fc->passive_created  = -1;
     fc->orig_server      = c->base_server;
+
+    fc->cwd              = apr_palloc(c->pool, APR_PATH_MAX + 1);
+    fc->cwd[0]           = '/';
+    fc->cwd[1]           = '\0';
+
+    fc->rename_from      = apr_palloc(c->pool, APR_PATH_MAX + 1);
+    fc->rename_from[0]   = '\0';
 
     fc->cntlsock  = ap_get_module_config(c->conn_config, &core_module);
     return apr_pool_create(&fc->data_pool, c->pool);



Mime
View raw message