daemon: further tweaks.
- Do validation only on canonicalized paths - Run upload-pack with "." as repository argument Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 21, 2005 at 01:21 UTC
ce335fe04f32261e0204280281989ffbb5d990c6
2 files changed
+14
-18
Documentation/git-daemon.txt
+2
-2
@@ -8,7 +8,7 @@ git-daemon - A really simple server for git repositories.
8
SYNOPSIS
9
--------
10
'git-daemon' [--verbose] [--syslog] [--inetd | --port=n] [--export-all]
11
- [--timeout=n] [--init-timeout=n] [directory...]
11
+ [--timeout=n] [--init-timeout=n] [--strict-paths] [directory...]
12
13
DESCRIPTION
14
-----------
@@ -29,7 +29,7 @@ This is ideally suited for read-only updates, ie pulling from git repositories.
29
30
OPTIONS
31
-------
32
-+--strict-paths::
32
+--strict-paths::
33
Match paths exactly (i.e. don't allow "/foo/repo" when the real path is
34
"/foo/repo.git" or "/foo/repo/.git") and don't do user-relative paths.
35
git-daemon will refuse to start when this option is enabled and no
daemon.c
+12
-16
@@ -92,25 +92,21 @@ static char *path_ok(char *dir)
92
}
93
94
if ( ok_paths && *ok_paths ) {
95
- char **pp = NULL;
96
- int dirlen = strlen(dir);
95
+ char **pp;
96
int pathlen = strlen(path);
97
98
+ /* The validation is done on the paths after enter_repo
99
+ * canonicalization, so whitelist should be written in
100
+ * terms of real pathnames (i.e. after ~user is expanded
101
+ * and symlinks resolved).
102
+ */
103
for ( pp = ok_paths ; *pp ; pp++ ) {
104
int len = strlen(*pp);
101
- /* because of symlinks we must match both what the
102
- * user passed and the canonicalized path, otherwise
103
- * the user can send a string matching either a whitelist
104
- * entry or an actual directory exactly and still not
105
- * get through */
106
- if (len <= pathlen && !memcmp(*pp, path, len)) {
107
- if (path[len] == '\0' || (!strict_paths && path[len] == '/'))
108
- return path;
109
- }
110
- if (len <= dirlen && !memcmp(*pp, dir, len)) {
111
- if (dir[len] == '\0' || (!strict_paths && dir[len] == '/'))
112
- return path;
113
- }
105
+ if (len <= pathlen &&
106
+ !memcmp(*pp, path, len) &&
107
+ (path[len] == '\0' ||
108
+ (!strict_paths && path[len] == '/')))
109
+ return path;
110
}
111
}
112
else {
@@ -160,7 +156,7 @@ static int upload(char *dir)
156
snprintf(timeout_buf, sizeof timeout_buf, "--timeout=%u", timeout);
157
158
/* git-upload-pack only ever reads stuff, so this is safe */
163
- execlp("git-upload-pack", "git-upload-pack", "--strict", timeout_buf, path, NULL);
159
+ execlp("git-upload-pack", "git-upload-pack", "--strict", timeout_buf, ".", NULL);
160
return -1;
161
}
162