e83cdd
From 95bbcaa8550534f03b332487ef3a2ed6650424fe Mon Sep 17 00:00:00 2001
e83cdd
From: Frantisek Sumsal <frantisek@sumsal.cz>
e83cdd
Date: Wed, 21 Aug 2019 11:16:07 +0200
e83cdd
Subject: [PATCH] git2spec: avoid malforming of SHA-1 hashes
e83cdd
e83cdd
When a SHA-1 hash of a specific commit is used as a tag, the regex
e83cdd
shenanigans later in the script can (and will) corrupt it in certain
e83cdd
cases.
e83cdd
e83cdd
e.g.:
e83cdd
$ perl -e '
e83cdd
$tag="6e8cd92261577230daa1098f7e05ec198c3c4281";
e83cdd
$tag=~s/[^0-9]+?([0-9]+)/$1/;
e83cdd
print("$tag\n");
e83cdd
'
e83cdd
68cd92261577230daa1098f7e05ec198c3c4281
e83cdd
e83cdd
(Notice the missing 'e')
e83cdd
e83cdd
Let's fix this by limiting the regex's scope to a non-SHA-1 tags only.
e83cdd
---
e83cdd
 git2spec.pl | 2 +-
e83cdd
 1 file changed, 1 insertion(+), 1 deletion(-)
e83cdd
e83cdd
diff --git a/git2spec.pl b/git2spec.pl
e83cdd
index 7853791e..9ddc3805 100755
e83cdd
--- a/git2spec.pl
e83cdd
+++ b/git2spec.pl
e83cdd
@@ -37,7 +37,7 @@ $tag=`git describe --abbrev=0 --tags` if not defined $tag;
e83cdd
 chomp($tag);
e83cdd
 my @patches=&create_patches($tag, $pdir);
e83cdd
 my $num=$#patches + 2;
e83cdd
-$tag=~s/[^0-9]+?([0-9]+)/$1/;
e83cdd
+$tag=~s/[^0-9]+?([0-9]+)/$1/ if $tag !~ /\b[0-9a-f]{5,40}\b/;
e83cdd
 my $release="$num.git$datestr";
e83cdd
 $release="1" if $num == 1;
e83cdd
 
e83cdd