Skip to content

Fix segfault when reading reflog with extra newlines #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ The public error API
bugs, but in the meantime, please code defensively and check for NULL
when calling this function.

- `void geterr_clear(void)`: This function clears the last error. The
- `void giterr_clear(void)`: This function clears the last error. The
library will call this when an error is generated by low level function
and the higher level function handles the error.

Expand Down
2 changes: 1 addition & 1 deletion src/refdb_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
entry = git__calloc(1, sizeof(git_reflog_entry));
GITERR_CHECK_ALLOC(entry);

entry->committer = git__malloc(sizeof(git_signature));
entry->committer = git__calloc(1, sizeof(git_signature));
GITERR_CHECK_ALLOC(entry->committer);

if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < 0)
Expand Down
16 changes: 16 additions & 0 deletions tests/refs/reflog/reflog.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_re
git_buf_free(&subtrees_log_path);
}

void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_returns_error(void)
{
git_reflog *reflog;
const git_error *error;

/* clear the error state so we can capture the error generated by git_reflog_read */
giterr_clear();

cl_git_fail(git_reflog_read(&reflog, g_repo, "refs/heads/extra-newline"));

error = giterr_last();

cl_assert(error != NULL);
cl_assert_equal_s("Unable to parse OID - contains invalid characters", error->message);
}

void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
{
git_reference *master, *new_master;
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/testrepo.git/logs/refs/heads/extra-newline
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0000000000000000000000000000000000000000 be3563ae3f795b2b4353bcce3a527ad0a4f7f644 Ben Straub <bstraub@github.com> 1335806563 -0800 clone: from
/Users/ben/src/libgit2/tests/resources/testrepo.git
be3563ae3f795b2b4353bcce3a527ad0a4f7f644 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1335806603 -0800 commit: checking in