diff options
author | Tony Finch <dot@dotat.at> | 2010-03-31 01:39:19 +0100 |
---|---|---|
committer | Ian Jackson <ian@liberator.relativity.greenend.org.uk> | 2010-05-22 15:54:41 +0100 |
commit | 5f3e811b5415dcff74f82bdd2f26d3af1f73c555 (patch) | |
tree | 32a6d03a4f062a9e02facea8bad6bcb99e65e10c /git-daemon | |
parent | 9ad7f5edd331027061b3d41bff050fe97d19b866 (diff) | |
download | userv-utils-5f3e811b5415dcff74f82bdd2f26d3af1f73c555.tar.gz |
git-daemon: fix and de-obfuscate the pkt-line parser.
Diffstat (limited to 'git-daemon')
-rwxr-xr-x | git-daemon/git-daemon.pl | 22 |
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 } |