From 2984ff86d913c3a9a9f53e67e141f7a39bf77160 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 5 Jun 2019 01:26:55 +0000 Subject: tighten up digit matches to ASCII for git output While I don't expect git to suddenly start spewing non-ASCII digits in places I'd expect ASCII, this would make things easier for future hackers and reviewers. --- lib/PublicInbox/Git.pm | 4 ++-- lib/PublicInbox/Import.pm | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 9014e021..68445b3c 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -141,7 +141,7 @@ again: } return; } - $head =~ /^[0-9a-f]{40} \S+ (\d+)$/ or + $head =~ /^[0-9a-f]{40} \S+ ([0-9]+)$/ or fail($self, "Unexpected result from git cat-file: $head"); my $size = $1; @@ -319,7 +319,7 @@ sub modified ($) { foreach my $oid (<$fh>) { chomp $oid; my $buf = cat_file($self, $oid) or next; - $$buf =~ /^committer .*?> (\d+) [\+\-]?\d+/sm or next; + $$buf =~ /^committer .*?> ([0-9]+) [\+\-]?[0-9]+/sm or next; my $cmt_time = $1; $modified = $cmt_time if $cmt_time > $modified; } diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 81a38fb6..2c4bad92 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -106,7 +106,7 @@ sub _cat_blob ($$$) { local $/ = "\n"; my $info = <$r>; defined $info or die "EOF from fast-import / cat-blob: $!"; - $info =~ /\A[a-f0-9]{40} blob (\d+)\n\z/ or return; + $info =~ /\A[a-f0-9]{40} blob ([0-9]+)\n\z/ or return; my $left = $1; my $offset = 0; my $buf = ''; @@ -493,9 +493,9 @@ sub clean_purge_buffer { foreach my $i (0..$#$buf) { my $l = $buf->[$i]; - if ($l =~ /^author .* (\d+ [\+-]?\d+)$/) { + if ($l =~ /^author .* ([0-9]+ [\+-]?[0-9]+)$/) { $buf->[$i] = "author <> $1\n"; - } elsif ($l =~ /^data (\d+)/) { + } elsif ($l =~ /^data ([0-9]+)/) { $buf->[$i++] = "data " . length($cmt_msg) . "\n"; $buf->[$i] = $cmt_msg; last; @@ -525,7 +525,7 @@ sub purge_oids { @buf = (); } push @buf, "commit $tmp\n"; - } elsif (/^data (\d+)/) { + } elsif (/^data ([0-9]+)/) { # only commit message, so $len is small: my $len = $1; # + 1 for trailing "\n" push @buf, $_; @@ -557,7 +557,7 @@ sub purge_oids { @buf = (); } elsif ($_ eq "done\n") { $done = 1; - } elsif (/^mark :(\d+)$/) { + } elsif (/^mark :([0-9]+)$/) { push @buf, $_; $mark = $1; } else { -- cgit v1.2.3-24-ge0c7