1
0
forked from aniani/gmnisrv

CGI: Fix paths which end in '/'

This commit is contained in:
Eyal Sawady 2020-11-15 10:54:36 -05:00 committed by Drew DeVault
parent 05a71905f9
commit 0646fd020c

View File

@ -407,21 +407,34 @@ serve_request(struct gmnisrv_client *client)
if ((n = stat(real_path, &st)) != 0) {
if (route->cgi) {
const char *new;
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);
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);
}
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),