Skip to content

Commit dbf0c5c

Browse files
committed
Merge pull request #2 from srajko/reflog-segfault-fix
Fix segfault when reading reflog with extra newlines
2 parents fe96502 + 05a1fc6 commit dbf0c5c

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

docs/error-handling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ The public error API
128128
bugs, but in the meantime, please code defensively and check for NULL
129129
when calling this function.
130130
131-
- `void geterr_clear(void)`: This function clears the last error. The
131+
- `void giterr_clear(void)`: This function clears the last error. The
132132
library will call this when an error is generated by low level function
133133
and the higher level function handles the error.
134134

src/refdb_fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
14531453
entry = git__calloc(1, sizeof(git_reflog_entry));
14541454
GITERR_CHECK_ALLOC(entry);
14551455

1456-
entry->committer = git__malloc(sizeof(git_signature));
1456+
entry->committer = git__calloc(1, sizeof(git_signature));
14571457
GITERR_CHECK_ALLOC(entry->committer);
14581458

14591459
if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < 0)

tests/refs/reflog/reflog.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_re
154154
git_buf_free(&subtrees_log_path);
155155
}
156156

157+
void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_returns_error(void)
158+
{
159+
git_reflog *reflog;
160+
const git_error *error;
161+
162+
/* clear the error state so we can capture the error generated by git_reflog_read */
163+
giterr_clear();
164+
165+
cl_git_fail(git_reflog_read(&reflog, g_repo, "refs/heads/extra-newline"));
166+
167+
error = giterr_last();
168+
169+
cl_assert(error != NULL);
170+
cl_assert_equal_s("Unable to parse OID - contains invalid characters", error->message);
171+
}
172+
157173
void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
158174
{
159175
git_reference *master, *new_master;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
0000000000000000000000000000000000000000 be3563ae3f795b2b4353bcce3a527ad0a4f7f644 Ben Straub <bstraub@github.com> 1335806563 -0800 clone: from
2+
/Users/ben/src/libgit2/tests/resources/testrepo.git
3+
be3563ae3f795b2b4353bcce3a527ad0a4f7f644 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1335806603 -0800 commit: checking in

0 commit comments

Comments
 (0)