summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2010-04-28 13:35:25 +0000
committerStefan Bühler <stbuehler@web.de>2010-04-28 13:35:25 +0000
commit494ce8e3b03124b4c9fe445464edab15250141f3 (patch)
tree54219c2ffec776649a972f12684451a415901aa5
parentf6b3c15024e53cde7a31f5bb86ab7c40ee741229 (diff)
downloadlighttpd-git-494ce8e3b03124b4c9fe445464edab15250141f3.tar.gz
[mod_compress] Fix segfault when etags are disabled (fixes #2169)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2723 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r--NEWS1
-rw-r--r--src/mod_compress.c37
2 files changed, 24 insertions, 14 deletions
diff --git a/NEWS b/NEWS
index a806bde7..25ecf40b 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ NEWS
* mod_proxy: close connection on write error (fixes #2114)
* Check uri instead of physical path for directory redirect
* Fix detecting git repository (fixes #2173, thx ncopa)
+ * [mod_compress] Fix segfault when etags are disabled (fixes #2169)
- 1.4.26 - 2010-02-07
* Fix request parser to handle packets with splitted \r\n\r\n (fixes #2105)
diff --git a/src/mod_compress.c b/src/mod_compress.c
index 12939506..748fc65e 100644
--- a/src/mod_compress.c
+++ b/src/mod_compress.c
@@ -744,6 +744,7 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
int accept_encoding = 0;
char *value = ds->value->ptr;
int matched_encodings = 0;
+ int use_etag = sce->etag != NULL && sce->etag->ptr != NULL;
/* get client side support encodings */
#ifdef USE_ZLIB
@@ -770,12 +771,14 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
mtime = strftime_cache_get(srv, sce->st.st_mtime);
/* try matching original etag of uncompressed version */
- etag_mutate(con->physical.etag, sce->etag);
- if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) {
- response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
- response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime));
- response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
- return HANDLER_FINISHED;
+ if (use_etag) {
+ etag_mutate(con->physical.etag, sce->etag);
+ if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) {
+ response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
+ response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime));
+ response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
+ return HANDLER_FINISHED;
+ }
}
/* select best matching encoding */
@@ -790,22 +793,26 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
compression_name = dflt_deflate;
}
- /* try matching etag of compressed version */
- buffer_copy_string_buffer(srv->tmp_buf, sce->etag);
- buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("-"));
- buffer_append_string(srv->tmp_buf, compression_name);
- etag_mutate(con->physical.etag, srv->tmp_buf);
+ if (use_etag) {
+ /* try matching etag of compressed version */
+ buffer_copy_string_buffer(srv->tmp_buf, sce->etag);
+ buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("-"));
+ buffer_append_string(srv->tmp_buf, compression_name);
+ etag_mutate(con->physical.etag, srv->tmp_buf);
+ }
if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) {
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name));
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime));
- response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
+ if (use_etag) {
+ response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
+ }
return HANDLER_FINISHED;
}
/* deflate it */
- if (p->conf.compress_cache_dir->used) {
+ if (use_etag && p->conf.compress_cache_dir->used) {
if (0 != deflate_file_to_file(srv, con, p, con->physical.path, sce, compression_type))
return HANDLER_GO_ON;
} else {
@@ -814,7 +821,9 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
}
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name));
response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime));
- response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
+ if (use_etag) {
+ response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
+ }
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
/* let mod_staticfile handle the cached compressed files, physical path was modified */
return p->conf.compress_cache_dir->used ? HANDLER_GO_ON : HANDLER_FINISHED;