]> git.proxmox.com Git - libgit2.git/blob - tests/refs/crashes.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / refs / crashes.c
1 #include "clar_libgit2.h"
2 #include "refs.h"
3
4 void test_refs_crashes__double_free(void)
5 {
6 git_repository *repo;
7 git_reference *ref, *ref2;
8 const char *REFNAME = "refs/heads/xxx";
9
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);
16
17 /* reference is gone from disk, so reloading it will fail */
18 cl_git_fail(git_reference_lookup(&ref2, repo, REFNAME));
19
20 cl_git_sandbox_cleanup();
21 }
22
23 void test_refs_crashes__empty_packedrefs(void)
24 {
25 git_repository *repo;
26 git_reference *ref;
27 const char *REFNAME = "refs/heads/xxx";
28 git_str temp_path = GIT_STR_INIT;
29 int fd = 0;
30
31 repo = cl_git_sandbox_init("empty_bare.git");
32
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));
37
38 /* should fail gracefully */
39 cl_git_fail_with(
40 GIT_ENOTFOUND, git_reference_lookup(&ref, repo, REFNAME));
41
42 cl_git_sandbox_cleanup();
43 git_str_dispose(&temp_path);
44 }