From 105dfa106c36e31b3f62c166cc46b97a6b0f7f51 Mon Sep 17 00:00:00 2001 From: Grzegorz Nosek Date: Sun, 16 Mar 2008 17:13:54 +0100 Subject: Chdir to script's directory before exec (per CGI spec) --- fcgiwrap.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'fcgiwrap.c') diff --git a/fcgiwrap.c b/fcgiwrap.c index c65f240..626518f 100644 --- a/fcgiwrap.c +++ b/fcgiwrap.c @@ -236,6 +236,7 @@ static void handle_fcgi_request() int pipe_out[2]; int pipe_err[2]; char *filename; + char *last_slash; pid_t pid; struct fcgi_context fc; @@ -254,6 +255,20 @@ static void handle_fcgi_request() puts("Status: 403 Forbidden\nContent-type: text/plain\n\n403"); exit(99); } + + last_slash = strrchr(filename, '/'); + if (!last_slash) { + puts("Status: 403 Forbidden\nContent-type: text/plain\n\n403"); + exit(99); + } + + *last_slash = 0; + if (chdir(filename) < 0) { + puts("Status: 403 Forbidden\nContent-type: text/plain\n\n403"); + exit(99); + } + *last_slash = '/'; + close(pipe_in[1]); close(pipe_out[0]); close(pipe_err[0]); -- cgit v1.2.3