openbsd-ports/www/lighttpd/patches/patch-src_mod_compress_c
sthen 18e7b066bb Add a lighttpd fix from upstream. From Brad.
- Disable mmap by default with mod_compress, if a user truncates a file we
are mmapping, reading the truncated area leads to SIGBUS.
2012-03-06 08:23:43 +00:00

102 lines
2.8 KiB
Plaintext

$OpenBSD: patch-src_mod_compress_c,v 1.4 2012/03/06 08:23:43 sthen Exp $
- Fix handling if etags are disabled but cache-dir is set - may lead to double response.
- Disable mmap by default (fixes #2391).
--- src/mod_compress.c.orig Sun Feb 26 00:15:43 2012
+++ src/mod_compress.c Sun Feb 26 00:15:33 2012
@@ -485,7 +485,7 @@ static int deflate_file_to_file(server *srv, connectio
return -1;
}
-
+#ifdef USE_MMAP
if (MAP_FAILED == (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) {
log_error_write(srv, __FILE__, __LINE__, "sbss", "mmaping", fn, "failed", strerror(errno));
@@ -499,7 +499,24 @@ static int deflate_file_to_file(server *srv, connectio
return -1;
}
+#else
+ start = malloc(sce->st.st_size);
+ if (NULL == start || sce->st.st_size != read(ifd, start, sce->st.st_size)) {
+ log_error_write(srv, __FILE__, __LINE__, "sbss", "reading", fn, "failed", strerror(errno));
+ close(ofd);
+ close(ifd);
+ free(start);
+
+ /* Remove the incomplete cache file, so that later hits aren't served from it */
+ if (-1 == unlink(p->ofn->ptr)) {
+ log_error_write(srv, __FILE__, __LINE__, "sbss", "unlinking incomplete cachefile", p->ofn, "failed:", strerror(errno));
+ }
+
+ return -1;
+ }
+#endif
+
switch(type) {
#ifdef USE_ZLIB
case HTTP_ACCEPT_ENCODING_GZIP:
@@ -530,7 +547,12 @@ static int deflate_file_to_file(server *srv, connectio
}
}
+#ifdef USE_MMAP
munmap(start, sce->st.st_size);
+#else
+ free(start);
+#endif
+
close(ofd);
close(ifd);
@@ -571,14 +593,24 @@ static int deflate_file_to_buffer(server *srv, connect
return -1;
}
-
+#ifdef USE_MMAP
if (MAP_FAILED == (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) {
log_error_write(srv, __FILE__, __LINE__, "sbss", "mmaping", fn, "failed", strerror(errno));
close(ifd);
return -1;
}
+#else
+ start = malloc(sce->st.st_size);
+ if (NULL == start || sce->st.st_size != read(ifd, start, sce->st.st_size)) {
+ log_error_write(srv, __FILE__, __LINE__, "sbss", "reading", fn, "failed", strerror(errno));
+ close(ifd);
+ free(start);
+ return -1;
+ }
+#endif
+
switch(type) {
#ifdef USE_ZLIB
case HTTP_ACCEPT_ENCODING_GZIP:
@@ -598,7 +630,11 @@ static int deflate_file_to_buffer(server *srv, connect
break;
}
+#ifdef USE_MMAP
munmap(start, sce->st.st_size);
+#else
+ free(start);
+#endif
close(ifd);
if (ret != 0) return -1;
@@ -826,7 +862,7 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
}
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;
+ return (use_etag && p->conf.compress_cache_dir->used) ? HANDLER_GO_ON : HANDLER_FINISHED;
}
}
}