summaryrefslogtreecommitdiff
path: root/git-daemon
diff options
context:
space:
mode:
authorTony Finch <dot@dotat.at>2010-03-31 01:39:19 +0100
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>2010-05-22 15:54:41 +0100
commit5f3e811b5415dcff74f82bdd2f26d3af1f73c555 (patch)
tree32a6d03a4f062a9e02facea8bad6bcb99e65e10c /git-daemon
parent9ad7f5edd331027061b3d41bff050fe97d19b866 (diff)
downloaduserv-utils-5f3e811b5415dcff74f82bdd2f26d3af1f73c555.tar.gz
git-daemon: fix and de-obfuscate the pkt-line parser.
Diffstat (limited to 'git-daemon')
-rwxr-xr-xgit-daemon/git-daemon.pl22
1 files changed, 12 insertions, 10 deletions
diff --git a/git-daemon/git-daemon.pl b/git-daemon/git-daemon.pl
index 91dd727..645cbc5 100755
--- a/git-daemon/git-daemon.pl
+++ b/git-daemon/git-daemon.pl
@@ -31,21 +31,23 @@ $SIG{ALRM} = sub { fail "timeout" };
alarm 30;
sub xread {
- my $length = shift; $_ = "";
- while ($length > length) {
- my $ret = sysread STDIN, $_, $length, length;
- fail "Expected $length bytes, got ".length
+ my $length = shift;
+ my $buffer = "";
+ while ($length > length $buffer) {
+ my $ret = sysread STDIN, $buffer, $length, length $buffer;
+ fail "Expected $length bytes, got ".length $buffer
if defined $ret and $ret == 0;
fail "read: $!" if not defined $ret and $! != EINTR and $! != EAGAIN;
}
+ return $buffer;
}
-xread 4;
-fail "Bad hex in packet length" unless m|^[0-9a-fA-F]{4}$|;
-xread hex;
-unless (($service,$path,$host) =
+my $hex_len = xread 4;
+fail "Bad hex in packet length" unless $hex_len =~ m|^[0-9a-fA-F]{4}$|;
+my $line = xread -4 + hex $hex_len;
+unless (($service,$path,$host) = $line =~
m|^(git-[a-z-]+) /*([!-~]+)\0host=([!-~]+)\0$|) {
- s|[^ -~]+| |g;
- fail "Could not parse \"$_\""
+ $line =~ s|[^ -~]+| |g;
+ fail "Could not parse \"$line\""
}
our $uri = $_ = "git://$host/$path";
for my $cf (@ARGV) { do $cf }