From: Tony Finch Date: Wed, 31 Mar 2010 00:39:19 +0000 (+0100) Subject: git-daemon: fix and de-obfuscate the pkt-line parser. X-Git-Tag: userv/0.6.1~100 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv-utils.git;a=commitdiff_plain;h=5f3e811b5415dcff74f82bdd2f26d3af1f73c555 git-daemon: fix and de-obfuscate the pkt-line parser. --- 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 }