From aff2da75984cb4b216ac47d4603dd5618d0942f7 Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 16 Apr 2014 14:43:43 +0000 Subject: My previous attempt to chdir(2) to the directory containing the cgi script was not quite right. slowcgi would try to chdir("") with a SCRIPT_NAME of /foo.cgi; chdir("/") in that case. I'm not sure how one would configure nginx/slowcgi to get to that point though. OK benno@ --- slowcgi.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/slowcgi.c b/slowcgi.c index 215c466..c27a74e 100644 --- a/slowcgi.c +++ b/slowcgi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slowcgi.c,v 1.30 2014/04/14 19:25:48 florian Exp $ */ +/* $OpenBSD: slowcgi.c,v 1.31 2014/04/16 14:43:43 florian Exp $ */ /* * Copyright (c) 2013 David Gwynne * Copyright (c) 2013 Florian Obser @@ -894,10 +894,15 @@ exec_cgi(struct request *c) path = strrchr(c->script_name, '/'); if (path != NULL) { - *path = '\0'; - if (chdir(c->script_name) == -1) - lwarn("cannot chdir to %s", c->script_name); - *path = '/'; + if (path != c->script_name) { + *path = '\0'; + if (chdir(c->script_name) == -1) + lwarn("cannot chdir to %s", + c->script_name); + *path = '/'; + } else + if (chdir("/") == -1) + lwarn("cannot chdir to /"); } argv[0] = c->script_name; -- cgit v1.2.3-2-gb3c3