forked from aniani/gmnisrv
CGI: Fix paths which end in '/'
This commit is contained in:
parent
05a71905f9
commit
0646fd020c
13
src/serve.c
13
src/serve.c
@ -407,21 +407,34 @@ serve_request(struct gmnisrv_client *client)
|
|||||||
if ((n = stat(real_path, &st)) != 0) {
|
if ((n = stat(real_path, &st)) != 0) {
|
||||||
if (route->cgi) {
|
if (route->cgi) {
|
||||||
const char *new;
|
const char *new;
|
||||||
|
size_t r = strlen(real_path);
|
||||||
|
if (real_path[r - 1] == '/') {
|
||||||
|
new = "";
|
||||||
|
} else {
|
||||||
strcpy(temp_path, client_path);
|
strcpy(temp_path, client_path);
|
||||||
new = basename((char *)temp_path);
|
new = basename((char *)temp_path);
|
||||||
|
}
|
||||||
|
|
||||||
size_t l = strlen(new), q = strlen(pathinfo);
|
size_t l = strlen(new), q = strlen(pathinfo);
|
||||||
memmove(&pathinfo[l + 1], pathinfo, q);
|
memmove(&pathinfo[l + 1], pathinfo, q);
|
||||||
pathinfo[0] = '/';
|
pathinfo[0] = '/';
|
||||||
memcpy(&pathinfo[1], new, l);
|
memcpy(&pathinfo[1], new, l);
|
||||||
|
|
||||||
|
if (real_path[r - 1] == '/') {
|
||||||
|
client_path[strlen(client_path) - 1] = '\0';
|
||||||
|
} else {
|
||||||
strcpy(temp_path, client_path);
|
strcpy(temp_path, client_path);
|
||||||
new = dirname((char *)temp_path);
|
new = dirname((char *)temp_path);
|
||||||
strcpy(client_path, new);
|
strcpy(client_path, new);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (real_path[r - 1] == '/') {
|
||||||
|
real_path[r - 1] = '\0';
|
||||||
|
} else {
|
||||||
strcpy(temp_path, real_path);
|
strcpy(temp_path, real_path);
|
||||||
new = dirname((char *)temp_path);
|
new = dirname((char *)temp_path);
|
||||||
strcpy(real_path, new);
|
strcpy(real_path, new);
|
||||||
|
}
|
||||||
|
|
||||||
if (route_match(route, client_path, &url_path)) {
|
if (route_match(route, client_path, &url_path)) {
|
||||||
n = snprintf(real_path, sizeof(real_path),
|
n = snprintf(real_path, sizeof(real_path),
|
||||||
|
Loading…
Reference in New Issue
Block a user