]> gitweb.ps.run Git - ps-cgit/blobdiff - cgit.c
tests: add tests for links with space in path and/or args
[ps-cgit] / cgit.c
diff --git a/cgit.c b/cgit.c
index 916feb4f10dd3f128a10381d39f139cfa318b9a9..e302a7c8c387cf096a4f387792c41223cc048b01 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -29,15 +29,17 @@ void add_mimetype(const char *name, const char *value)
 struct cgit_filter *new_filter(const char *cmd, int extra_args)
 {
        struct cgit_filter *f;
+       int args_size = 0;
 
        if (!cmd || !cmd[0])
                return NULL;
 
        f = xmalloc(sizeof(struct cgit_filter));
        f->cmd = xstrdup(cmd);
-       f->argv = xmalloc((2 + extra_args) * sizeof(char *));
+       args_size = (2 + extra_args) * sizeof(char *);
+       f->argv = xmalloc(args_size);
+       memset(f->argv, 0, args_size);
        f->argv[0] = f->cmd;
-       f->argv[1] = NULL;
        return f;
 }
 
@@ -752,10 +754,11 @@ int main(int argc, const char **argv)
        http_parse_querystring(ctx.qry.raw, querystring_cb);
 
        /* If virtual-root isn't specified in cgitrc, lets pretend
-        * that virtual-root equals SCRIPT_NAME.
+        * that virtual-root equals SCRIPT_NAME, minus any possibly
+        * trailing slashes.
         */
        if (!ctx.cfg.virtual_root)
-               ctx.cfg.virtual_root = ctx.cfg.script_name;
+               ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/');
 
        /* If no url parameter is specified on the querystring, lets
         * use PATH_INFO as url. This allows cgit to work with virtual