summaryrefslogtreecommitdiff
path: root/src/refspec.c
diff options
context:
space:
mode:
authorVicent Marti <vicent@github.com>2014-08-25 18:18:06 +0200
committerVicent Marti <vicent@github.com>2014-08-25 18:18:06 +0200
commit2c1de697e04bf19e55efef415fcf0ec3e592511a (patch)
tree1fd5fcb4ab3b4f71e0d6716617d1b198c2a7c438 /src/refspec.c
parentd28b2b7a5ff608ce8f3da0e0b6a4c75afcf1e82c (diff)
parent8f6073f63e42c2a3ff3b6fbb20729c7a911be30f (diff)
downloadlibgit2-2c1de697e04bf19e55efef415fcf0ec3e592511a.tar.gz
Merge pull request #2527 from jacquesg/refspec-crash
Check if the refspec matches before transforming
Diffstat (limited to 'src/refspec.c')
-rw-r--r--src/refspec.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/refspec.c b/src/refspec.c
index 77c58c84e..9f0df35a7 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -223,7 +223,13 @@ static int refspec_transform(
int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name)
{
- git_buf_sanitize(out);
+ assert(out && spec && name);
+ git_buf_sanitize(out);
+
+ if (!git_refspec_src_matches(spec, name)) {
+ giterr_set(GITERR_INVALID, "ref '%s' doesn't match the source", name);
+ return -1;
+ }
if (!spec->pattern)
return git_buf_puts(out, spec->dst);
@@ -233,7 +239,13 @@ int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *nam
int git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name)
{
- git_buf_sanitize(out);
+ assert(out && spec && name);
+ git_buf_sanitize(out);
+
+ if (!git_refspec_dst_matches(spec, name)) {
+ giterr_set(GITERR_INVALID, "ref '%s' doesn't match the destination", name);
+ return -1;
+ }
if (!spec->pattern)
return git_buf_puts(out, spec->src);