Readd arguments after realpath after latest printelem() changes. - geomyidae - A small C-based gopherd. HTML git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 3401df4e6802a68dd34581ae0de6b7e34f45ea12 DIR parent 6f22091df20685c8b7a8a89823aa31606bea2be0 HTML Author: Christoph Lohmann <20h@r-36.net> Date: Mon, 5 Apr 2021 22:05:11 +0200 Readd arguments after realpath after latest printelem() changes. Diffstat: M ind.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- DIR diff --git a/ind.c b/ind.c @@ -403,7 +403,7 @@ scanfile(char *fname) int printelem(int fd, Elems *el, char *file, char *base, char *addr, char *port) { - char *path, *p, *argbase, buf[PATH_MAX+1]; + char *path, *p, *argbase, buf[PATH_MAX+1], *argp; int len, blen; if (!strcmp(el->e[3], "server")) { @@ -439,6 +439,7 @@ printelem(int fd, Elems *el, char *file, char *base, char *addr, char *port) else len = strlen(path); + /* Strip off arguments for realpath. */ argbase = strchr(el->e[2], '?'); if (argbase != NULL) blen = argbase - el->e[2]; @@ -451,8 +452,18 @@ printelem(int fd, Elems *el, char *file, char *base, char *addr, char *port) if ((path = realpath(buf, NULL)) && !strncmp(base, path, strlen(base))) { p = path + strlen(base); + + /* + * Do not forget to readd arguments which were + * stripped off. + */ + if (argbase != NULL) + argp = smprintf("%s%s", p[0]? p : "/", argbase); + else + argp = xstrdup(p[0]? p : "/"); + free(el->e[2]); - el->e[2] = xstrdup(p[0]? p : "/"); + el->e[2] = argp; } free(path); }