fallback to lseek()/read() if mmap() fails (#fixes 2666)
commit8e3c6bf754c4e7ad7cea5ba524ca36ec204a2b44
authorGlenn Strauss <gstrauss@gluelogic.com>
Mon, 18 Apr 2016 03:37:40 +0000 (17 23:37 -0400)
committerGlenn Strauss <gstrauss@gluelogic.com>
Thu, 28 Apr 2016 17:13:36 +0000 (28 13:13 -0400)
tree8637d12de5144cf816e5799e133f499704b5b70b
parentc9b56735b87ddd6dd68f12e9476089f70502fc7b
fallback to lseek()/read() if mmap() fails (#fixes 2666)

fallback to lseek()/read() if mmap() fails (#fixes 2666)
e.g. when mmap() is used on lighttpd-controlled temporary files
used POST request body (mod_cgi) and PUT file upload (mod_webdav)

replace use of stream_open() on potentially untrusted files
(protect against SIGBUS if a file is modified while map is read)
Note: stream.[ch] may be removed in a future release
For now, stream.[ch] will read entire file into memory if mmap fails
and so it should only be used on trusted files, e.g. config files.

http_auth basic and digest files are typically small and so buffered
stdio fopen(), fgets(), fclose() will likely be approximately as fast
as mmap.

mod_dirlisting header and readme files are typically small and so
open(), read(), close() will typically be approximately as fast as mmap

mod_ssi will likely be much faster, now buffering SSI page construction
rather than a potentially huge number of file open() calls, one for each
tiny chunk of text between SSI directives.

mod_webdav COPY and MOVE may be slower due to removal of mmap, but are
now more resilient to partial writes.

x-ref:
  "handle filesystems without mmap() support"
  https://redmine.lighttpd.net/issues/2666
  "WebDAV upload-> mmap failed: operation not permitted"
  https://redmine.lighttpd.net/issues/962
  "Lighttpd 1.4.20 Crash (SIGBUS in mod_compress)"
  https://redmine.lighttpd.net/issues/1879
  "Crash SIGBUS"
  https://redmine.lighttpd.net/issues/2391

github: closes #57
src/http_auth.c
src/mod_cgi.c
src/mod_dirlisting.c
src/mod_ssi.c
src/mod_webdav.c
src/stream.c
src/stream.h