]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Merge r756671, r756675, r756678, r756683 from trunk:
authorJim Jagielski <jim@apache.org>
Fri, 17 Apr 2009 13:42:03 +0000 (13:42 +0000)
committerJim Jagielski <jim@apache.org>
Fri, 17 Apr 2009 13:42:03 +0000 (13:42 +0000)
Creation of external gzip process fails, if we
try to set the working directory to r->filename.
Use ap_make_dirstr_parent() instead, like in all
other similar places.

Creating the external gzip process fails, because we
call execve() with "gzip" without full path.
Let's look for it in the PATH instead and drop the
passing of the environment. There seems to be no
reason why gzip should need the httpd environment.

Set the content encoding for compressed content
even if we can't detect the content type of the
uncompressed content.

When trying to detect the content type of the
uncompressed content it is often not enough
to read the same number of bytes, we already
read compressed. Since uncompress() allocates a
new buffer, we can increase the number of bytes
to read to the same size, we use in the case,
where the content isn't compressed.

Furthermore zero-terminate the read data to keep
assumptions consistent with the uncompressed case.

Submitted by: rjung
Reviewed/backported by: jim

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@765999 13f79535-47bb-0310-9956-ffa450edef68

STATUS
modules/metadata/mod_mime_magic.c

diff --git a/STATUS b/STATUS
index 906244eb7ff21ec30786018bc182c9e1a41d0d61..f994d8ed245111962fd36b08e851b2a38d7a5771 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -95,25 +95,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
- * mod_mime_magic: For compressed content the module sets the
-   content encoding header and also tries to determine the
-   uncompressed content type by using an external gzip.
-   Several bugs break this functionality:
-   - Starting gzip doesn't work because an invalid working
-     directory is used and neither the full path name for gzip
-     nor the PATH variable is used.
-   - When gzip works, but cannot detect the content type, then
-     content encoding is also not set.
-   - Too few bytes are uncompressed so often the content type
-     can not be determined.
-   Patches in trunk (separated to make review easier):
-     http://svn.apache.org/viewvc?rev=756671&view=rev (working dir)
-     http://svn.apache.org/viewvc?rev=756675&view=rev (use PATH)
-     http://svn.apache.org/viewvc?rev=756678&view=rev (content encoding)
-     http://svn.apache.org/viewvc?rev=756683&view=rev (read more bytes)
-   Those patches apply to 2.2.x as well.
-   +1: rjung, rpluem, jim
-
  * mod_substitute: Avoid endless loops in substitution.
    Trunk version of patch:
       http://svn.apache.org/viewvc?rev=755190&view=rev
index cd6279112a620cf4974e478c7372e2b83a7e3d2f..867a4964eb56a5a23485fc3ae89790914b2d1911 100644 (file)
@@ -2099,13 +2099,15 @@ static int zmagic(request_rec *r, unsigned char *buf, apr_size_t nbytes)
     if (i == ncompr)
         return 0;
 
-    if ((newsize = uncompress(r, i, &newbuf, nbytes)) > 0) {
+    if ((newsize = uncompress(r, i, &newbuf, HOWMANY)) > 0) {
+        /* set encoding type in the request record */
+        r->content_encoding = compr[i].encoding;
+
+        newbuf[newsize-1] = '\0';  /* null-terminate uncompressed data */
+        /* Try to detect the content type of the uncompressed data */
         if (tryit(r, newbuf, newsize, 0) != OK) {
             return 0;
         }
-
-        /* set encoding type in the request record */
-        r->content_encoding = compr[i].encoding;
     }
     return 1;
 }
@@ -2121,7 +2123,6 @@ static int create_uncompress_child(struct uncompress_parms *parm, apr_pool_t *cn
 {
     int rc = 1;
     const char *new_argv[4];
-    const char *const *env;
     request_rec *r = parm->r;
     apr_pool_t *child_context = cntxt;
     apr_procattr_t *procattr;
@@ -2133,13 +2134,12 @@ static int create_uncompress_child(struct uncompress_parms *parm, apr_pool_t *cn
      * Should we create the err pipe, read it, and copy to the log?
      */
 
-    env = (const char *const *)ap_create_environment(child_context, r->subprocess_env);
-
     if ((apr_procattr_create(&procattr, child_context) != APR_SUCCESS) ||
         (apr_procattr_io_set(procattr, APR_FULL_BLOCK,
                            APR_FULL_BLOCK, APR_NO_PIPE)   != APR_SUCCESS) ||
-        (apr_procattr_dir_set(procattr, r->filename)        != APR_SUCCESS) ||
-        (apr_procattr_cmdtype_set(procattr, APR_PROGRAM)    != APR_SUCCESS)) {
+        (apr_procattr_dir_set(procattr,
+                              ap_make_dirstr_parent(r->pool, r->filename)) != APR_SUCCESS) ||
+        (apr_procattr_cmdtype_set(procattr, APR_PROGRAM_PATH) != APR_SUCCESS)) {
         /* Something bad happened, tell the world. */
         ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_ENOPROC, r,
                "couldn't setup child process: %s", r->filename);
@@ -2152,7 +2152,7 @@ static int create_uncompress_child(struct uncompress_parms *parm, apr_pool_t *cn
 
         procnew = apr_pcalloc(child_context, sizeof(*procnew));
         rc = apr_proc_create(procnew, compr[parm->method].argv[0],
-                               new_argv, env, procattr, child_context);
+                               new_argv, NULL, procattr, child_context);
 
         if (rc != APR_SUCCESS) {
             /* Bad things happened. Everyone should have cleaned up. */
@@ -2473,5 +2473,3 @@ module AP_MODULE_DECLARE_DATA mime_magic_module =
     mime_magic_cmds,           /* command apr_table_t */
     register_hooks              /* register hooks */
 };
-
-