From fc5c2a1b41bb7ab7a5813302371a2af000ff3dcc Mon Sep 17 00:00:00 2001 From: prx Date: Thu, 18 Aug 2022 14:12:38 +0200 Subject: [PATCH] fix cgi and simplify now we use regex --- main.c | 8 ++------ vger.c | 7 +++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index 1ba03ee..4cde739 100644 --- a/main.c +++ b/main.c @@ -67,17 +67,13 @@ main(int argc, char **argv) if (*cgi_dir) if (do_cgi(chroot_dir, cgi_dir, path, hostname, query) == 0) stop(EXIT_SUCCESS, NULL); + /* *** from here, cgi didn't run *** */ - syslog(LOG_DAEMON, "path:%s", path); - /* *** from here, cgi didn't run *** - * check if path available - */ + /* check if path available */ check_path(path, sizeof(path), virtualhost, strlen(hostname)); /* split dir and filename */ split_dir_file(path, dir, sizeof(dir), file, sizeof(file)); - syslog(LOG_DAEMON, "dir:%s", dir); - syslog(LOG_DAEMON, "file:%s", file); /* go to dir */ if (*dir) diff --git a/vger.c b/vger.c index 1fe1a8c..f942c86 100644 --- a/vger.c +++ b/vger.c @@ -220,7 +220,6 @@ do_cgi(const char *chroot_dir, const char *cgi_dir, const char *path, const char /* check if path starts with cgi_dir * compare beginning of path with cgi_dir - * path + 2 : skip "./" * cgi_dir + strlen(chrootdir) (skip chrootdir) */ @@ -229,7 +228,7 @@ do_cgi(const char *chroot_dir, const char *cgi_dir, const char *path, const char while (*cgirp == '/') estrlcpy(cgirp, cgirp+1, sizeof(cgirp)); - if (strncmp(cgirp, path+2, strlen(cgirp)) != 0) + if (strncmp(cgirp, path, strlen(cgirp)) != 0) return 1; /* not in cgi_dir, go to display_file */ /* set env variables for CGI @@ -250,11 +249,11 @@ do_cgi(const char *chroot_dir, const char *cgi_dir, const char *path, const char */ /* find next item after cgi_dir in path: - * path + 2 (skip "./") + strlen(cgirp) + 1 (skip '/') + * path + strlen(cgirp) + 1 (skip '/') */ /* cgi file to execute */ - estrlcpy(cgifp, path + 2 + strlen(cgirp) + 1, sizeof(cgifp)); + estrlcpy(cgifp, path + strlen(cgirp) + 1, sizeof(cgifp)); if (!(*cgifp)) /* problem with cgi file, abort */ return 1;