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