]>
git.proxmox.com Git - libgit2.git/blob - tests/refs/crashes.c
4f508aed2f4a556ca25a7f82b92e17dee19f8155
1 #include "clar_libgit2.h"
4 void test_refs_crashes__double_free(void)
7 git_reference
*ref
, *ref2
;
8 const char *REFNAME
= "refs/heads/xxx";
10 repo
= cl_git_sandbox_init("testrepo.git");
11 cl_git_pass(git_reference_symbolic_create(&ref
, repo
, REFNAME
, "refs/heads/master", 0, NULL
));
12 cl_git_pass(git_reference_lookup(&ref2
, repo
, REFNAME
));
13 cl_git_pass(git_reference_delete(ref
));
14 git_reference_free(ref
);
15 git_reference_free(ref2
);
17 /* reference is gone from disk, so reloading it will fail */
18 cl_git_fail(git_reference_lookup(&ref2
, repo
, REFNAME
));
20 cl_git_sandbox_cleanup();
23 void test_refs_crashes__empty_packedrefs(void)
27 const char *REFNAME
= "refs/heads/xxx";
28 git_str temp_path
= GIT_STR_INIT
;
31 repo
= cl_git_sandbox_init("empty_bare.git");
33 /* create zero-length packed-refs file */
34 cl_git_pass(git_str_joinpath(&temp_path
, git_repository_path(repo
), GIT_PACKEDREFS_FILE
));
35 cl_git_pass(((fd
= p_creat(temp_path
.ptr
, 0644)) < 0));
36 cl_git_pass(p_close(fd
));
38 /* should fail gracefully */
40 GIT_ENOTFOUND
, git_reference_lookup(&ref
, repo
, REFNAME
));
42 cl_git_sandbox_cleanup();
43 git_str_dispose(&temp_path
);