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:
and we need to strip it off to understand their request.
After 5ad312bede, we send the host attribute but no newline,
Both of these are parsed correctly by git-daemon. But if
some client were to combine the two:
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
and end up with:
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
Reported-by: Michael Haggerty <firstname.lastname@example.org>
Signed-off-by: Jeff King <email@example.com>
Signed-off-by: Junio C Hamano <firstname.lastname@example.org>