remove extra slash from request path if it is in a chroot - geomyidae - A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
 (HTM) git clone git://r-36.net/geomyidae
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 980a398da8acca65a13936ff0792c39f3dcb0ede
 (DIR) parent 7d7fc25a935fe9a9093abe93f678fa7a9bfd6549
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Sat, 18 Feb 2023 12:29:29 +0100
       
       remove extra slash from request path if it is in a chroot
       
       Remove extra slash from request path if it is in a chroot.
       This is because a chroot sets base to "/", otherwise "/" at the end were
       already stripped.
       
       This also fixes the $PATH_TRANSLATED environment variable in CGI scripts.
       
       Signed-off-by: Christoph Lohmann <20h@r-36.net>
       
       Diffstat:
         M main.c                              |       5 ++++-
       
       1 file changed, 4 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/main.c b/main.c
       @@ -248,7 +248,10 @@ handlerequest(int sock, char *req, int rlen, char *base, char *ohost,
                        return;
                }
        
       -        if (snprintf(path, sizeof(path), "%s%s", base, recvb) > sizeof(path)) {
       +        /* append base to request path (always starting with /), if base is a chroot don't append '/' */
       +        if (snprintf(path, sizeof(path), "%s%s",
       +            base[0] == '/' && base[1] == '\0' ? "" : base,
       +            recvb) > sizeof(path)) {
                        if (loglvl & ERRORS) {
                                logentry(clienth, clientp, recvc,
                                        "path truncation occurred");