From 83885891f583ab447f98f1c7a637f1f507e1be22 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Sun, 4 Nov 2012 22:01:24 -0800 Subject: [PATCH 1/7] Bail out if remote->url would be NULL This fixes a crash from attempting to invoke git__strdup() against NULL. --- src/remote.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/remote.c b/src/remote.c index 47bcaf95f..187e3953a 100644 --- a/src/remote.c +++ b/src/remote.c @@ -131,6 +131,11 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name) if ((error = git_config_get_string(&val, config, git_buf_cstr(&buf))) < 0) goto cleanup; + + if (!val) { + error = -1; + goto cleanup; + } remote->repo = repo; remote->url = git__strdup(val); From a2a618948c38d381a741c5799b87f7ff62da8c65 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 5 Nov 2012 07:49:37 +0100 Subject: [PATCH 2/7] remote: Add malformed remote load test --- tests-clar/network/remotes.c | 11 +++++++++-- tests-clar/resources/testrepo.git/config | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c index 21a3aaa41..d53b1723f 100644 --- a/tests-clar/network/remotes.c +++ b/tests-clar/network/remotes.c @@ -183,13 +183,13 @@ void test_network_remotes__list(void) git_config *cfg; cl_git_pass(git_remote_list(&list, _repo)); - cl_assert(list.count == 3); + cl_assert(list.count == 4); git_strarray_free(&list); cl_git_pass(git_repository_config(&cfg, _repo)); cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com")); cl_git_pass(git_remote_list(&list, _repo)); - cl_assert(list.count == 4); + cl_assert(list.count == 5); git_strarray_free(&list); git_config_free(cfg); @@ -269,3 +269,10 @@ void test_network_remotes__tagopt(void) git_config_free(cfg); } + +void test_network_remotes__cannot_load_with_an_empty_url(void) +{ + git_remote *remote; + + cl_git_fail(git_remote_load(&remote, _repo, "empty-remote-url")); +} diff --git a/tests-clar/resources/testrepo.git/config b/tests-clar/resources/testrepo.git/config index 54ff6109b..3801ce08d 100644 --- a/tests-clar/resources/testrepo.git/config +++ b/tests-clar/resources/testrepo.git/config @@ -8,6 +8,8 @@ fetch = +refs/heads/*:refs/remotes/test/* [remote "joshaber"] url = git://github.com/libgit2/libgit2 +[remote "empty-remote-url"] + url = [remote "test_with_pushurl"] url = git://github.com/libgit2/fetchlibgit2 From f8baece754d24a6121d701e2bad1922c61cffe71 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 5 Nov 2012 10:42:10 -0800 Subject: [PATCH 3/7] Set GITERR_INVALID when encountering a NULL remote URL --- src/remote.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/remote.c b/src/remote.c index 187e3953a..714e2f0a9 100644 --- a/src/remote.c +++ b/src/remote.c @@ -133,6 +133,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name) goto cleanup; if (!val) { + geterr_set(GITERR_INVALID, "Malformed remote '%s' - missing URL", name); error = -1; goto cleanup; } From 1fe99aeea3d9e2a5b9637f3d76273335e6366e36 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 5 Nov 2012 10:44:48 -0800 Subject: [PATCH 4/7] Test for GITERR_INVALID --- tests-clar/network/remotes.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c index d53b1723f..1d58aba75 100644 --- a/tests-clar/network/remotes.c +++ b/tests-clar/network/remotes.c @@ -275,4 +275,5 @@ void test_network_remotes__cannot_load_with_an_empty_url(void) git_remote *remote; cl_git_fail(git_remote_load(&remote, _repo, "empty-remote-url")); + cl_assert(giterr_last()->klass == GITERR_INVALID); } From f358ec143c8c9952227d31cd21c24f8c9be23d3c Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 5 Nov 2012 10:45:26 -0800 Subject: [PATCH 5/7] Don't expect the 'empty-remote-url' remote to be listed CC @nulltoken --- tests-clar/network/remotes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c index 1d58aba75..481dece5c 100644 --- a/tests-clar/network/remotes.c +++ b/tests-clar/network/remotes.c @@ -183,13 +183,13 @@ void test_network_remotes__list(void) git_config *cfg; cl_git_pass(git_remote_list(&list, _repo)); - cl_assert(list.count == 4); + cl_assert(list.count == 3); git_strarray_free(&list); cl_git_pass(git_repository_config(&cfg, _repo)); cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com")); cl_git_pass(git_remote_list(&list, _repo)); - cl_assert(list.count == 5); + cl_assert(list.count == 4); git_strarray_free(&list); git_config_free(cfg); From 6edefa149126955dbdf1c866ef5b2ec85be5031a Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 5 Nov 2012 10:58:08 -0800 Subject: [PATCH 6/7] Revert "Don't expect the 'empty-remote-url' remote to be listed" Apparently git_remote_list() includes even remotes for which git_remote_load() would fail. Sorry @nulltoken, false alarm. This reverts commit f358ec143c8c9952227d31cd21c24f8c9be23d3c. --- tests-clar/network/remotes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c index 481dece5c..1d58aba75 100644 --- a/tests-clar/network/remotes.c +++ b/tests-clar/network/remotes.c @@ -183,13 +183,13 @@ void test_network_remotes__list(void) git_config *cfg; cl_git_pass(git_remote_list(&list, _repo)); - cl_assert(list.count == 3); + cl_assert(list.count == 4); git_strarray_free(&list); cl_git_pass(git_repository_config(&cfg, _repo)); cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com")); cl_git_pass(git_remote_list(&list, _repo)); - cl_assert(list.count == 4); + cl_assert(list.count == 5); git_strarray_free(&list); git_config_free(cfg); From c1cd036e409b874932f3da83624809e0a9bc9b47 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 5 Nov 2012 11:01:00 -0800 Subject: [PATCH 7/7] 'geterr' -> 'giterr' --- src/remote.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/remote.c b/src/remote.c index 714e2f0a9..a873a27b6 100644 --- a/src/remote.c +++ b/src/remote.c @@ -133,7 +133,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name) goto cleanup; if (!val) { - geterr_set(GITERR_INVALID, "Malformed remote '%s' - missing URL", name); + giterr_set(GITERR_INVALID, "Malformed remote '%s' - missing URL", name); error = -1; goto cleanup; }