[mod_cgi] use MAP_PRIVATE to mmap temporary file instead of MAP_SHARED (fixes #2715)

Flash filesystem JFFS2 does not support mmap PROT_READ MAP_SHARED,
though it does support mmap PROT_READ MAP_PRIVATE

Although MAP_SHARED is preferred, CGI input body is fully collected
prior to handler invoking the CGI, so the temporary file is never
modified after being mapped.  Since the request input body is specific
to request and is temporary file, mmap PROT_READ MAP_PRIVATE works fine.

From: Glenn Strauss <gstrauss@gluelogic.com>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3075 152afb58-edef-0310-8abb-c4023f1b3aa9
Glenn Strauss 7 years ago committed by Stefan Bühler
parent 1a71c13869
commit 3fd80ff8ec
  1. 1
  2. 4

@ -8,6 +8,7 @@ NEWS
* add handling for lua 5.2 and 5.3 (fixes #2674)
* use libmemcached instead of deprecated libmemcache
* add force_assert for more allocation results
* [mod_cgi] use MAP_PRIVATE to mmap temporary file (fixes #2715)
- 1.4.39 - 2016-01-02
* [core] fix memset_s call (fixes #2698)

@ -10,13 +10,13 @@
#include "plugin.h"
#include <sys/types.h>
#include "sys-mmap.h"
#ifdef __WIN32
# include <winsock2.h>
# include <sys/socket.h>
# include <sys/wait.h>
# include <sys/mman.h>
# include <netinet/in.h>
# include <arpa/inet.h>
@ -776,7 +776,7 @@ static int cgi_write_file_chunk_mmap(server *srv, connection *con, int fd, chunk
c->file.mmap.offset = mmap_align_offset(offset);
c->file.mmap.length = file_end - c->file.mmap.offset;
if (MAP_FAILED == (c->file.mmap.start = mmap(NULL, c->file.mmap.length, PROT_READ, MAP_SHARED, c->file.fd, c->file.mmap.offset))) {
if (MAP_FAILED == (c->file.mmap.start = mmap(NULL, c->file.mmap.length, PROT_READ, MAP_PRIVATE, c->file.fd, c->file.mmap.offset))) {
log_error_write(srv, __FILE__, __LINE__, "ssbdoo", "mmap failed:",
strerror(errno), c->file.name, c->file.fd, c->file.mmap.offset, (off_t) c->file.mmap.length);
return -1;