summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEyal Sawady <ecs@d2evs.net>2020-11-15 10:54:36 -0500
committerDrew DeVault <sir@cmpwn.com>2020-11-15 10:55:48 -0500
commit0646fd020c37362ecb25b4a5c01f984c5090166e (patch)
tree106d532a51a4bfc07f92eb6470bdce70e98a5405 /src
parent05a71905f959765fad74232b42dee6118b6f2029 (diff)
downloadgmnisrv-0646fd020c37362ecb25b4a5c01f984c5090166e.tar.gz
gmnisrv-0646fd020c37362ecb25b4a5c01f984c5090166e.tar.xz
gmnisrv-0646fd020c37362ecb25b4a5c01f984c5090166e.zip
CGI: Fix paths which end in '/'
Diffstat (limited to 'src')
-rw-r--r--src/serve.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/serve.c b/src/serve.c
index 11a34f2..677b6a4 100644
--- a/src/serve.c
+++ b/src/serve.c
@@ -407,21 +407,34 @@ serve_request(struct gmnisrv_client *client)
if ((n = stat(real_path, &st)) != 0) {
if (route->cgi) {
const char *new;
- strcpy(temp_path, client_path);
- new = basename((char *)temp_path);
+ size_t r = strlen(real_path);
+ if (real_path[r - 1] == '/') {
+ new = "";
+ } else {
+ strcpy(temp_path, client_path);
+ new = basename((char *)temp_path);
+ }
size_t l = strlen(new), q = strlen(pathinfo);
memmove(&pathinfo[l + 1], pathinfo, q);
pathinfo[0] = '/';
memcpy(&pathinfo[1], new, l);
- strcpy(temp_path, client_path);
- new = dirname((char *)temp_path);
- strcpy(client_path, new);
+ if (real_path[r - 1] == '/') {
+ client_path[strlen(client_path) - 1] = '\0';
+ } else {
+ strcpy(temp_path, client_path);
+ new = dirname((char *)temp_path);
+ strcpy(client_path, new);
+ }
- strcpy(temp_path, real_path);
- new = dirname((char *)temp_path);
- strcpy(real_path, new);
+ if (real_path[r - 1] == '/') {
+ real_path[r - 1] = '\0';
+ } else {
+ strcpy(temp_path, real_path);
+ new = dirname((char *)temp_path);
+ strcpy(real_path, new);
+ }
if (route_match(route, client_path, &url_path)) {
n = snprintf(real_path, sizeof(real_path),