patch for git-daemon base-path trailing '/' problem

From: Aneesh Bhasin <hidden>
Date: 2016-06-15 22:46:49
Subsystem: the rest · Maintainer: Linus Torvalds

Hi All,

I was trying to setup git-daemon on our server with the following args :

git-daemon --base-path=/git_repo/ --export-all --syslog --inetd
--verbose /git_repo/external_repos/

There are two git repos in /git_repo/external_repos/ :-
linux-test/.git and linux-release/.git

When I try to clone the linux-test/.git repo using :
git clone 192.168.1.100/external_repos/linux-test

I get an error at the server side from git-daemon saying that
"/git_repo//external/repos/linux-test/.git not in whitelist".

The problem is because fo the trailing '/' in base-path in git-daemon
args. I think it might be fairly common that a person might add a '/'
at the end of base-path. The following patch takes care of this
trailing patch :

diff --git a/daemon.c b/daemon.c
index daa4c8e..cd4dfed 100644
--- a/daemon.c
+++ b/daemon.c
@@ -209,11 +209,15 @@ static char *path_ok(char *directory)
                dir = interp_path;
        }
        else if (base_path) {
+    int base_pathlen;
                if (*dir != '/') {
                        /* Allow only absolute */
                        logerror("'%s': Non-absolute path denied (base-path acti
                        return NULL;
                }
+    base_pathlen = strlen(base_path);
+    if(base_path[base_pathlen-1]=='/')
+      base_path[base_pathlen-1]='\0';
                snprintf(rpath, PATH_MAX, "%s%s", base_path, dir);
                dir = rpath;
        }
@@ -229,7 +233,7 @@ static char *path_ok(char *directory)
        }


---------------------------------------
Regards,
Aneesh Bhasin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help