From 48bde2f1b62d24f3982382d520bfac887537641d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 8 Mar 2013 02:11:34 +0100 Subject: [PATCH] config: don't allow passing NULL as a value to set Passing NULL is non-sensical. The error message leaves to be desired, though, as it leaks internal implementation details. Catch it at the `git_config_set_string` level and set an appropriate error message. --- src/config.c | 5 +++++ tests-clar/config/write.c | 14 ++++++++++++++ tests-clar/online/fetchhead.c | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index d6aa3078c..c7022891d 100644 --- a/src/config.c +++ b/src/config.c @@ -362,6 +362,11 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value) git_config_backend *file; file_internal *internal; + if (!value) { + giterr_set(GITERR_CONFIG, "The value to set cannot be NULL"); + return -1; + } + internal = git_vector_get(&cfg->files, 0); file = internal->file; diff --git a/tests-clar/config/write.c b/tests-clar/config/write.c index 1b665cd19..d70612a97 100644 --- a/tests-clar/config/write.c +++ b/tests-clar/config/write.c @@ -228,3 +228,17 @@ void test_config_write__add_value_at_file_with_no_clrf_at_the_end(void) git_config_free(cfg); } + +void test_config_write__can_set_a_value_to_NULL(void) +{ + git_repository *repository; + git_config *config; + + repository = cl_git_sandbox_init("testrepo.git"); + + cl_git_pass(git_repository_config(&config, repository)); + cl_git_fail(git_config_set_string(config, "a.b.c", NULL)); + git_config_free(config); + + cl_git_sandbox_cleanup(); +} diff --git a/tests-clar/online/fetchhead.c b/tests-clar/online/fetchhead.c index 84a2177ea..a8a5bb918 100644 --- a/tests-clar/online/fetchhead.c +++ b/tests-clar/online/fetchhead.c @@ -79,8 +79,8 @@ void test_online_fetchhead__no_merges(void) fetchhead_test_clone(); cl_git_pass(git_repository_config(&config, g_repo)); - cl_git_pass(git_config_set_string(config, "branch.master.remote", NULL)); - cl_git_pass(git_config_set_string(config, "branch.master.merge", NULL)); + cl_git_pass(git_config_delete_entry(config, "branch.master.remote")); + cl_git_pass(git_config_delete_entry(config, "branch.master.merge")); git_config_free(config); fetchhead_test_fetch(NULL, FETCH_HEAD_NO_MERGE_DATA);