From: Jim Jagielski Date: Fri, 18 Dec 2009 14:13:05 +0000 (+0000) Subject: * mod_disk_cache, mod_mem_cache: don't cache incomplete responses, X-Git-Tag: 2.2.15~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5210e9c0cf5581cb5ab8502afbb0c2fd330ef679;p=thirdparty%2Fapache%2Fhttpd.git * mod_disk_cache, mod_mem_cache: don't cache incomplete responses, per RFC 2616, 13.8. PR 15866 Trunk Patch: http://svn.apache.org/viewvc?rev=818492&view=rev http://svn.apache.org/viewvc?rev=821763&view=rev 2.2.x Patch: http://people.apache.org/~poirier/PR15866-22x.patch +1: poirier, rpluem, rjung, jim git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@892260 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 79f44ad2028..d79c54eb35e 100644 --- a/CHANGES +++ b/CHANGES @@ -27,6 +27,9 @@ Changes with Apache 2.2.15 for the default values of 1024 for LdapCacheEntries/LdapOpCacheEntries. PR 46749. [Stefan Fritsch] + *) mod_disk_cache, mod_mem_cache: don't cache incomplete responses, + per RFC 2616, 13.8. PR15866. [Dan Poirier] + *) mod_rewrite: Make sure that a hostname:port isn't fully qualified if the request is a CONNECT request. PR 47928 [Bill Zajac ] diff --git a/STATUS b/STATUS index dd4a80114f6..19bc96e05ce 100644 --- a/STATUS +++ b/STATUS @@ -87,14 +87,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - * mod_disk_cache, mod_mem_cache: don't cache incomplete responses, - per RFC 2616, 13.8. - PR 15866 - Trunk Patch: http://svn.apache.org/viewvc?rev=818492&view=rev - http://svn.apache.org/viewvc?rev=821763&view=rev - 2.2.x Patch: http://people.apache.org/~poirier/PR15866-22x.patch - +1: poirier, rpluem, rjung, jim - * mod_filter: dispatch correctly where dispatch string doesn't exist PR 48054 Trunk patch: n/a (trunk upgraded to use ap_expr for condition testing) diff --git a/modules/cache/mod_disk_cache.c b/modules/cache/mod_disk_cache.c index 70a804b8955..7c50cd05cbc 100644 --- a/modules/cache/mod_disk_cache.c +++ b/modules/cache/mod_disk_cache.c @@ -1041,6 +1041,8 @@ static apr_status_t store_body(cache_handle_t *h, request_rec *r, * sanity checks. */ if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(bb))) { + const char *cl_header = apr_table_get(r->headers_out, "Content-Length"); + if (r->connection->aborted || r->no_cache) { ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, "disk_cache: Discarding body for URL %s " @@ -1059,6 +1061,17 @@ static apr_status_t store_body(cache_handle_t *h, request_rec *r, file_cache_errorcleanup(dobj, r); return APR_EGENERAL; } + if (cl_header) { + apr_size_t cl = apr_atoi64(cl_header); + if ((errno == 0) && (dobj->file_size != cl)) { + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, + "disk_cache: URL %s didn't receive complete response, not caching", + h->cache_obj->key); + /* Remove the intermediate cache file and return non-APR_SUCCESS */ + file_cache_errorcleanup(dobj, r); + return APR_EGENERAL; + } + } /* All checks were fine. Move tempfile to final destination */ /* Link to the perm file, and close the descriptor */ diff --git a/modules/cache/mod_mem_cache.c b/modules/cache/mod_mem_cache.c index 48bd785c50a..0edf0ffa424 100644 --- a/modules/cache/mod_mem_cache.c +++ b/modules/cache/mod_mem_cache.c @@ -745,6 +745,16 @@ static apr_status_t store_body(cache_handle_t *h, request_rec *r, apr_bucket_bri apr_size_t len; if (APR_BUCKET_IS_EOS(e)) { + const char *cl_header = apr_table_get(r->headers_out, "Content-Length"); + if (cl_header) { + apr_size_t cl = apr_atoi64(cl_header); + if ((errno == 0) && (obj->count != cl)) { + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, + "mem_cache: URL %s didn't receive complete response, not caching", + h->cache_obj->key); + return APR_EGENERAL; + } + } if (mobj->m_len > obj->count) { /* Caching a streamed response. Reallocate a buffer of the * correct size and copy the streamed response into that