aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorian2014-04-16 14:43:43 +0000
committerWynn Wolf Arbor2020-05-24 12:33:55 +0200
commitaff2da75984cb4b216ac47d4603dd5618d0942f7 (patch)
tree1e4843853d43a52371dc4ce8e44b4768646213f9
parent66a9a2015cd5871e5df35a3c793153c151c30812 (diff)
downloadslowcgi-aff2da75984cb4b216ac47d4603dd5618d0942f7.tar.gz
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@
-rw-r--r--slowcgi.c15
1 files 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 <dlg@openbsd.org>
* Copyright (c) 2013 Florian Obser <florian@openbsd.org>
@@ -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;