mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 04:34:15 +00:00
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.
This commit is contained in:
parent
92ebbe99c9
commit
48bde2f1b6
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user