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