Skip to content

Commit f4e9644

Browse files
committed
Merge branch 'kd/cvsimport-avoid-invalid-tag'
"cvsimport" tried to create a tag taken from CVS without sufficiently sanitizing it, causing the import to fail when an invalid character in the tagname made underlying "git tag" to fail. * kd/cvsimport-avoid-invalid-tag: cvsimport: strip all inappropriate tag strings
2 parents 067a1f5 + 70b67b0 commit f4e9644

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

git-cvsimport.perl

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,37 @@ sub commit {
889889
$xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **
890890
$xtag =~ tr/_/\./ if ( $opt_u );
891891
$xtag =~ s/[\/]/$opt_s/g;
892-
$xtag =~ s/\[//g;
893892

894-
system('git' , 'tag', '-f', $xtag, $cid) == 0
895-
or die "Cannot create tag $xtag: $!\n";
893+
# See refs.c for these rules.
894+
# Tag cannot contain bad chars. (See bad_ref_char in refs.c.)
895+
$xtag =~ s/[ ~\^:\\\*\?\[]//g;
896+
# Other bad strings for tags:
897+
# (See check_refname_component in refs.c.)
898+
1 while $xtag =~ s/
899+
(?: \.\. # Tag cannot contain '..'.
900+
| \@{ # Tag cannot contain '@{'.
901+
| ^ - # Tag cannot begin with '-'.
902+
| \.lock $ # Tag cannot end with '.lock'.
903+
| ^ \. # Tag cannot begin...
904+
| \. $ # ...or end with '.'
905+
)//xg;
906+
# Tag cannot be empty.
907+
if ($xtag eq '') {
908+
warn("warning: ignoring tag '$tag'",
909+
" with invalid tagname\n");
910+
return;
911+
}
912+
913+
if (system('git' , 'tag', '-f', $xtag, $cid) != 0) {
914+
# We did our best to sanitize the tag, but still failed
915+
# for whatever reason. Bail out, and give the user
916+
# enough information to understand if/how we should
917+
# improve the translation in the future.
918+
if ($tag ne $xtag) {
919+
print "Translated '$tag' tag to '$xtag'\n";
920+
}
921+
die "Cannot create tag $xtag: $!\n";
922+
}
896923

897924
print "Created tag '$xtag' on '$branch'\n" if $opt_v;
898925
}

0 commit comments

Comments
 (0)