fix cgi checking

make sure to look for files *after* the cgidir bit. should now work with
virtualhost and cgi, as it doesn't just blindly find the first slash.
This commit is contained in:
aabacchus 2021-11-02 11:11:03 +00:00
parent bb4be69207
commit 99f4310188
Signed by: phoebos
GPG Key ID: B02F7D053AC351D3
1 changed files with 12 additions and 1 deletions

13
main.c
View File

@ -38,6 +38,7 @@ void echdir (const char *);
void status (const int, const char *);
void status_redirect(const int, const char *);
void status_error(const int, const char *);
void strip_trailing_slash(char *path);
int uridecode (char *);
@ -304,6 +305,14 @@ cgi(const char *cgicmd)
exit(1);
}
void
strip_trailing_slash(char *path)
{
size_t len = strlen(path);
while (path[len - 1] == '/')
path[len-- - 1] = '\0';
}
int
main(int argc, char **argv)
{
@ -461,13 +470,15 @@ main(int argc, char **argv)
/* find the string of cgidir without chroot_dir prefix */
char tmp [PATH_MAX] = {'\0'};
char *cgipp;
strip_trailing_slash(chroot_dir);
strip_trailing_slash(cgidir);
estrlcpy(tmp, cgidir + strlen(chroot_dir), sizeof(tmp));
cgipp = tmp;
if (tmp[0] == '/')
cgipp++;
if (docgi && strncmp(dir, cgipp, strlen(cgipp)) == 0) {
pos = strchr(dir, '/');
pos = strchr(dir+strlen(cgipp), '/');
} else {
pos = strrchr(dir, '/');
}