summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-01-25 00:58:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-01-25 21:50:17 (GMT)
commited15e58efefc7f9dc1281860289e48e8f9c9b8fa (patch)
tree80da67171cc87e3fc59988a2bc34f30babb8bc40
parent4414a150025765bdf83df81026270b0acbb8b376 (diff)
downloadgit-ed15e58efefc7f9dc1281860289e48e8f9c9b8fa.zip
git-ed15e58efefc7f9dc1281860289e48e8f9c9b8fa.tar.gz
git-ed15e58efefc7f9dc1281860289e48e8f9c9b8fa.tar.bz2
daemon: fix length computation in newline stripping
When git-daemon gets a pktline request, we strip off any trailing newline, replacing it with a NUL. Clients prior to 5ad312bede (in git v1.4.0) would send: git-upload-pack repo.git\n and we need to strip it off to understand their request. After 5ad312bede, we send the host attribute but no newline, like: git-upload-pack repo.git\0host=example.com\0 Both of these are parsed correctly by git-daemon. But if some client were to combine the two: git-upload-pack repo.git\n\0host=example.com\0 we don't parse it correctly. The problem is that we use the "len" variable to record the position of the NUL separator, but then decrement it when we strip the newline. So we start with: git-upload-pack repo.git\n\0host=example.com\0 ^-- len and end up with: git-upload-pack repo.git\0\0host=example.com\0 ^-- len This is arguably correct, since "len" tells us the length of the initial string, but we don't actually use it for that. What we do use it for is finding the offset of the extended attributes; they used to be at len+1, but are now at len+2. We can solve that by just leaving "len" where it is. We don't have to care about the length of the shortened string, since we just treat it like a C string. No version of Git ever produced such a string, but it seems like the daemon code meant to handle this case (and it seems like a reasonable thing for somebody to do in a 3rd-party implementation). Reported-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--daemon.c6
-rwxr-xr-xt/t5570-git-daemon.sh15
2 files changed, 17 insertions, 4 deletions
diff --git a/daemon.c b/daemon.c
index 652f89b..72dfeaf 100644
--- a/daemon.c
+++ b/daemon.c
@@ -760,10 +760,8 @@ static int execute(void)
alarm(0);
len = strlen(line);
- if (len && line[len-1] == '\n') {
- line[--len] = 0;
- pktlen--;
- }
+ if (len && line[len-1] == '\n')
+ line[len-1] = 0;
/* parse additional args hidden behind a NUL byte */
if (len != pktlen)
diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh
index b556469..755b05a 100755
--- a/t/t5570-git-daemon.sh
+++ b/t/t5570-git-daemon.sh
@@ -196,5 +196,20 @@ test_expect_success 'daemon log records all attributes' '
test_cmp expect actual
'
+test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
+ {
+ printf "git-upload-pack /interp.git\n\0host=localhost" | packetize
+ printf "0000"
+ } >input &&
+ fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&
+ depacketize <output >output.raw &&
+
+ # just pick out the value of master, which avoids any protocol
+ # particulars
+ perl -lne "print \$1 if m{^(\\S+) refs/heads/master}" <output.raw >actual &&
+ git -C "$repo" rev-parse master >expect &&
+ test_cmp expect actual
+'
+
stop_git_daemon
test_done