diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-05-17 15:19:22 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-05-28 15:32:20 +0200 |
commit | c6e942fb3d10d9f8f2e22833ddddbd945c0d6604 (patch) | |
tree | d5257c00aaa122fc73bcd0d9e496c1c63fa36a56 /src | |
parent | ae5b93629c148dc96de7337095fba4b1e901ee2b (diff) | |
download | libgit2-c6e942fb3d10d9f8f2e22833ddddbd945c0d6604.tar.gz |
remote: validate refspecs before adding to config
When we moved from acting on the instance to acting on the
configuration, we dropped the validation of the passed refspec, which
can lead to writing an invalid refspec to the configuration. Bring that
validation back.
Diffstat (limited to 'src')
-rw-r--r-- | src/remote.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/remote.c b/src/remote.c index d58927f28..99b5bacc0 100644 --- a/src/remote.c +++ b/src/remote.c @@ -97,6 +97,7 @@ static int write_add_refspec(git_repository *repo, const char *name, const char { git_config *cfg; git_buf var = GIT_BUF_INIT; + git_refspec spec; const char *fmt; int error; @@ -108,6 +109,15 @@ static int write_add_refspec(git_repository *repo, const char *name, const char if ((error = ensure_remote_name_is_valid(name)) < 0) return error; + if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0) { + if (giterr_last()->klass != GITERR_NOMEMORY) + error = GIT_EINVALIDSPEC; + + return error; + } + + git_refspec__free(&spec); + if ((error = git_buf_printf(&var, fmt, name)) < 0) return error; |