diff options
author | Grzegorz Nosek <root@localdomain.pl> | 2015-04-19 11:29:48 +0200 |
---|---|---|
committer | Grzegorz Nosek <root@localdomain.pl> | 2015-04-19 11:31:21 +0200 |
commit | caf1f5c7b3e9cf5b777139c0419d47fa933ff510 (patch) | |
tree | f97715d602bf9b02e012aba93ac02fec11eef048 | |
parent | ff11e97f2eddca17427eaf0277c5efa853e58958 (diff) | |
parent | d6095c7d9ed4a182734eb080776d37d7f730f7d9 (diff) | |
download | fcgiwrap-caf1f5c7b3e9cf5b777139c0419d47fa933ff510.tar.xz fcgiwrap-caf1f5c7b3e9cf5b777139c0419d47fa933ff510.zip |
Merge branch 'fcgi_chdir' of git://github.com/philpennock/fcgiwrap
Fixes: https://github.com/gnosek/fcgiwrap/pull/21
-rw-r--r-- | fcgiwrap.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -521,6 +521,7 @@ static void handle_fcgi_request(void) int pipe_err[2]; char *filename; char *last_slash; + char *p; pid_t pid; struct fcgi_context fc; @@ -559,15 +560,22 @@ static void handle_fcgi_request(void) if (!is_allowed_program(filename)) cgi_error("403 Forbidden", "The given script is not allowed to execute", filename); - last_slash = strrchr(filename, '/'); - if (!last_slash) - cgi_error("403 Forbidden", "Script name must be a fully qualified path", filename); + p = getenv("FCGI_CHDIR"); + if (p == NULL) { + last_slash = strrchr(filename, '/'); + if (!last_slash) + cgi_error("403 Forbidden", "Script name must be a fully qualified path", filename); - *last_slash = 0; - if (chdir(filename) < 0) - cgi_error("403 Forbidden", "Cannot chdir to script directory", filename); + *last_slash = 0; + if (chdir(filename) < 0) + cgi_error("403 Forbidden", "Cannot chdir to script directory", filename); - *last_slash = '/'; + *last_slash = '/'; + } else if (strcmp(p, "-") != 0) { + if (chdir(p) < 0) { + cgi_error("403 Forbidden", "Cannot chdir to FCGI_CHDIR directory", p); + } + } execl(filename, filename, (void *)NULL); cgi_error("502 Bad Gateway", "Cannot execute script", filename); |