strip / at the end of the base path - geomyidae - A small C-based gopherd.
(HTM) git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
(DIR) commit 2760fe803a9ea8574dd7fa57b17708f283b5dbe0
(DIR) parent baf4df6c6481209962d0fa861dcbb6b9d69467a6
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Thu, 13 Sep 2018 20:42:13 +0200
strip / at the end of the base path
this fixes relative path handling when using:
geomyidae -b /var/gopher/ (added slash).
Signed-off-by: Christoph Lohmann <20h@r-36.net>
Diffstat:
M main.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
---
(DIR) diff --git a/main.c b/main.c
@@ -44,7 +44,7 @@ int revlookup = 1;
char *logfile = NULL;
char *argv0;
-char *stdbase = "/var/gopher";
+char stdbase[] = "/var/gopher";
char *stdport = "70";
char *indexf[] = {"/index.gph", "/index.cgi", "/index.dcgi", "/index.bin"};
char *nocgierr = "3Sorry, execution of the token '%s' was requested, but this "
@@ -374,7 +374,7 @@ main(int argc, char *argv[])
socklen_t cltlen;
int sock, dofork, inetf, usechroot, nocgi;
char *port, *base, clienth[NI_MAXHOST], clientp[NI_MAXSERV];
- char *user, *group, *bindip, *ohost, *sport;
+ char *user, *group, *bindip, *ohost, *sport, *p;
struct passwd *us;
struct group *gr;
@@ -538,6 +538,10 @@ main(int argc, char *argv[])
return 1;
}
+ /* strip / at the end, except if it is "/" */
+ for (p = base + strlen(base); p > base + 1 && p[-1] == '/'; --p)
+ p[-1] = '\0';
+
if (dropprivileges(gr, us) < 0) {
perror("dropprivileges");
close(listfd);