Browse Source

[mod_cgi] edge case chdir "/" when docroot "/" (fixes #2460)

From: Glenn Strauss <gstrauss@gluelogic.com>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3077 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/heads/lighttpd-1.4.x
Glenn Strauss 6 years ago
committed by Stefan Bühler
parent
commit
665cc39b95
  1. 1
      NEWS
  2. 7
      src/mod_cgi.c

1
NEWS

@ -10,6 +10,7 @@ NEWS
* add force_assert for more allocation results
* [mod_cgi] use MAP_PRIVATE to mmap temporary file (fixes #2715)
* [core] do not send SIGHUP to process group unless server.max-workers is used (fixes #2711)
* [mod_cgi] edge case chdir "/" when docroot "/" (fixes #2460)
- 1.4.39 - 2016-01-02
* [core] fix memset_s call (fixes #2698)

7
src/mod_cgi.c

@ -1075,10 +1075,13 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, buffer *
/* search for the last / */
if (NULL != (c = strrchr(con->physical.path->ptr, '/'))) {
*c = '\0';
/* handle special case of file in root directory */
const char* physdir = (c == con->physical.path->ptr) ? "/" : con->physical.path->ptr;
/* temporarily shorten con->physical.path to directory without terminating '/' */
*c = '\0';
/* change to the physical directory */
if (-1 == chdir(con->physical.path->ptr)) {
if (-1 == chdir(physdir)) {
log_error_write(srv, __FILE__, __LINE__, "ssb", "chdir failed:", strerror(errno), con->physical.path);
}
*c = '/';

Loading…
Cancel
Save