Skip to content

Crash calling Repository.IsValid with corrupt .git/config #1851

Open
@BruceMellows

Description

@BruceMellows

Reproduction steps

Add this to .git/config
[diff "mytool"] command = c:\path\to\my\tool\MyToolComparer.exe
This will cause the following effect for git

c:\my\git\repo> git status
fatal: bad config line 8 in file .git/config

Then call Repository.IsValid(@"c:\my\git\repo\.git") which is turn calls Proxy.git_repository_open_ext(path, RepositoryOpenFlags.NoSearch, null);

This fails because the return value from NativeMethods.git_repository_open_ext(out repo, path, flags, ceilingDirs) is not checked for error prior to freeing the out parameter repo (which is already free'd when there is an error condition in int git_repository_open_ext(git_repository **repo_ptr, const char *start_path, unsigned int flags, const char *ceiling_dirs))

Expected behavior

LibGit2Sharp.LibGit2SharpException

Actual behavior

Access violation (0xC0000005) in void git_repository_free(git_repository *repo) when dereferencing the null repo

Version of LibGit2Sharp (release number or SHA1)

0.27.0.34

Operating system(s) tested; .NET runtime tested

Windows 10 Pro 1909 - .NET CLR Version v4.0.30319

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions