chiark / gitweb /
git-daemon: fix and de-obfuscate the pkt-line parser.
authorTony Finch <dot@dotat.at>
Wed, 31 Mar 2010 00:39:19 +0000 (01:39 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 22 May 2010 14:54:41 +0000 (15:54 +0100)
git-daemon/git-daemon.pl

index 91dd7277ee6acbc43a8ec93222d71381e1821225..645cbc5bce9b0f4c7a2cfcc553fd7887d47dbcf2 100755 (executable)
@@ -31,21 +31,23 @@ $SIG{ALRM} = sub { fail "timeout" };
 alarm 30;
 
 sub xread {
 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;
     }
                             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$|) {
         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 }
 }
 our $uri = $_ = "git://$host/$path";
 for my $cf (@ARGV) { do $cf }