cgi: compare the physical path instead of the url to detect quirky urls
authorFelix Fietkau <nbd@openwrt.org>
Sat, 22 Mar 2014 19:31:35 +0000 (20:31 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 22 Mar 2014 19:32:29 +0000 (20:32 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
cgi.c
main.c
uhttpd.h

diff --git a/cgi.c b/cgi.c
index c4438b06153978c1b59c78bb19b527d4006e9d77..62be0a376f77c6c3f31478c74377744a6379f27a 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -103,7 +103,7 @@ static bool check_cgi_path(struct path_info *pi, const char *url)
        }
 
        pi->ip = NULL;
-       return uh_path_match(conf.cgi_prefix, url);
+       return uh_path_match(conf.cgi_docroot_path, pi->phys);
 }
 
 struct dispatch_handler cgi_dispatch = {
diff --git a/main.c b/main.c
index e53a3114c52e76e9c1dfe22c6b49387a5a2ee4d1..99a4025da72c2cb886ddebe9a7facd405a33f455 100644 (file)
--- a/main.c
+++ b/main.c
@@ -183,6 +183,13 @@ static void init_defaults_post(void)
        uh_index_add("index.htm");
        uh_index_add("default.html");
        uh_index_add("default.htm");
+
+       if (conf.cgi_prefix) {
+               char *str = malloc(strlen(conf.docroot) + strlen(conf.cgi_prefix) + 1);
+               strcpy(str, conf.docroot);
+               strcat(str, conf.cgi_prefix);
+               conf.cgi_docroot_path = str;
+       };
 }
 
 static void fixup_prefix(char *str)
@@ -406,12 +413,6 @@ int main(int argc, char **argv)
        }
 
        uh_config_parse();
-       init_defaults_post();
-
-       if (!bound) {
-               fprintf(stderr, "Error: No sockets bound, unable to continue\n");
-               return 1;
-       }
 
        if (!conf.docroot) {
                if (!realpath(".", uh_buf)) {
@@ -421,6 +422,13 @@ int main(int argc, char **argv)
                conf.docroot = strdup(uh_buf);
        }
 
+       init_defaults_post();
+
+       if (!bound) {
+               fprintf(stderr, "Error: No sockets bound, unable to continue\n");
+               return 1;
+       }
+
 #ifdef HAVE_TLS
        if (n_tls) {
                if (!tls_crt || !tls_key) {
index cace950fc41b0d4bc26b907ff2f4c0f9f38f0004..daf68cecb39b9dbebffb547ecb20b0897ea4ede9 100644 (file)
--- a/uhttpd.h
+++ b/uhttpd.h
@@ -52,6 +52,7 @@ struct config {
        const char *file;
        const char *error_handler;
        const char *cgi_prefix;
+       const char *cgi_docroot_path;
        const char *cgi_path;
        const char *lua_handler;
        const char *lua_prefix;