Skip to content

Commit 5731dfc

Browse files
bonzinigitster
authored andcommitted
request-pull: quote regex metacharacters in local ref
The local part of the third argument of git-request-pull is used in a regular expression without quoting it. Use qr{} and \Q\E to ensure that e.g. a period in a tag name does not match any character on the remote side. Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb582a commit 5731dfc

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

git-request-pull.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,18 @@ die "fatal: No commits in common between $base and $head"
8383
# Otherwise find a random ref that matches $headrev.
8484
find_matching_ref='
8585
my ($head,$headrev) = (@ARGV);
86+
my $pattern = qr{/\Q$head\E$};
8687
my ($found);
8788
8889
while (<STDIN>) {
8990
chomp;
9091
my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
91-
my ($pattern);
9292
next unless ($sha1 eq $headrev);
9393
94-
$pattern="/$head\$";
9594
if ($ref eq $head) {
9695
$found = $ref;
9796
}
98-
if ($ref =~ /$pattern/) {
97+
if ($ref =~ $pattern) {
9998
$found = $ref;
10099
}
101100
if ($sha1 eq $head) {

t/t5150-request-pull.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,22 @@ test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
246246
247247
'
248248

249+
test_expect_success 'request-pull quotes regex metacharacters properly' '
250+
251+
rm -fr downstream.git &&
252+
git init --bare downstream.git &&
253+
(
254+
cd local &&
255+
git checkout initial &&
256+
git merge --ff-only master &&
257+
git tag -mrelease v2.0 &&
258+
git push origin refs/tags/v2.0:refs/tags/v2-0 &&
259+
test_must_fail git request-pull initial "$downstream_url" tags/v2.0 \
260+
2>../err
261+
) &&
262+
grep "No match for commit .*" err &&
263+
grep "Are you sure you pushed" err
264+
265+
'
266+
249267
test_done

0 commit comments

Comments
 (0)