mirror of
https://git.proxmox.com/git/libgit2
synced 2025-12-16 16:21:40 +00:00
Deploy git_config_backend version
This commit is contained in:
parent
b81aa2f1de
commit
6917762139
15
src/config.c
15
src/config.c
@ -248,6 +248,18 @@ int git_config_open_level(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool config_backend_has_valid_version(git_config_backend *backend)
|
||||||
|
{
|
||||||
|
if (!backend)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (backend->version > 0 && backend->version <= GIT_CONFIG_BACKEND_VERSION)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
giterr_set(GITERR_INVALID, "Invalid version %d for git_config_backend", backend->version);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int git_config_add_backend(
|
int git_config_add_backend(
|
||||||
git_config *cfg,
|
git_config *cfg,
|
||||||
git_config_backend *file,
|
git_config_backend *file,
|
||||||
@ -259,6 +271,9 @@ int git_config_add_backend(
|
|||||||
|
|
||||||
assert(cfg && file);
|
assert(cfg && file);
|
||||||
|
|
||||||
|
if (!config_backend_has_valid_version(file))
|
||||||
|
return -1;
|
||||||
|
|
||||||
if ((result = file->open(file, level)) < 0)
|
if ((result = file->open(file, level)) < 0)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|||||||
@ -545,10 +545,10 @@ int git_config_file__ondisk(git_config_backend **out, const char *path)
|
|||||||
{
|
{
|
||||||
diskfile_backend *backend;
|
diskfile_backend *backend;
|
||||||
|
|
||||||
backend = git__malloc(sizeof(diskfile_backend));
|
backend = git__calloc(1, sizeof(diskfile_backend));
|
||||||
GITERR_CHECK_ALLOC(backend);
|
GITERR_CHECK_ALLOC(backend);
|
||||||
|
|
||||||
memset(backend, 0x0, sizeof(diskfile_backend));
|
backend->parent.version = GIT_CONFIG_BACKEND_VERSION;
|
||||||
|
|
||||||
backend->file_path = git__strdup(path);
|
backend->file_path = git__strdup(path);
|
||||||
GITERR_CHECK_ALLOC(backend->file_path);
|
GITERR_CHECK_ALLOC(backend->file_path);
|
||||||
|
|||||||
20
tests-clar/config/backend.c
Normal file
20
tests-clar/config/backend.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "clar_libgit2.h"
|
||||||
|
|
||||||
|
void test_config_backend__checks_version(void)
|
||||||
|
{
|
||||||
|
git_config *cfg;
|
||||||
|
git_config_backend backend = GIT_CONFIG_BACKEND_INIT;
|
||||||
|
backend.version = 1024;
|
||||||
|
const git_error *err;
|
||||||
|
|
||||||
|
cl_git_pass(git_config_new(&cfg));
|
||||||
|
cl_git_fail(git_config_add_backend(cfg, &backend, 0, false));
|
||||||
|
err = giterr_last();
|
||||||
|
cl_assert_equal_i(GITERR_INVALID, err->klass);
|
||||||
|
|
||||||
|
giterr_clear();
|
||||||
|
backend.version = 1024;
|
||||||
|
cl_git_fail(git_config_add_backend(cfg, &backend, 0, false));
|
||||||
|
err = giterr_last();
|
||||||
|
cl_assert_equal_i(GITERR_INVALID, err->klass);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user