Skip to content
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

ref.log() crashes on the reflog created by Repository.references.create() #901

Closed
cjerdonek opened this issue Apr 19, 2019 · 4 comments
Closed

Comments

@cjerdonek
Copy link
Contributor

If you create a new reference using Repository.references.create(), then an invalid (corrupt) reflog file gets created (e.g. can't be read by ref.log()).

This looks to be because e.g. Repository_create_reference_direct passes NULL to git_reference_create() as the log_message argument:

err = git_reference_create(&c_reference, self->repo, c_name, &oid, force, NULL);

And similarly for Repository_create_reference_symbolic:

pygit2/src/repository.c

Lines 1527 to 1528 in c43db44

err = git_reference_symbolic_create(&c_reference, self->repo, c_name,
c_target, force, NULL);

@cjerdonek
Copy link
Contributor Author

Actually, I think the issue isn't with writing, but with reading a file containing a line with no log message. ref.log() will crash if the log message is NULL:

py_entry->message = strdup(git_reflog_entry_message(entry));

@cjerdonek cjerdonek changed the title Repository.references.create() creates corrupt reflog file ref.log() crashes on the reflog created by Repository.references.create() Apr 19, 2019
@jdavid
Copy link
Member

jdavid commented May 11, 2019

Can you provide a complete example? I cannot reproduce it.

@cjerdonek
Copy link
Contributor Author

This is what I'm getting:

ref = repo.references['refs/heads/master']
list(ref.log())  # works
ref = repo.references.create('refs/heads/foo', ref.target)
list(ref.log())  # crashes

@jdavid jdavid closed this as completed in 907d54f May 13, 2019
@cjerdonek
Copy link
Contributor Author

Thanks!

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 11, 2019
0.28.2 (2019-05-26)
-------------------------

- Fix crash in reflog iteration
  `#901 <https://github.com/libgit2/pygit2/issues/901>`_

- Support symbolic references in ``branches.with_commit(..)``
  `#910 <https://github.com/libgit2/pygit2/issues/910>`_

- Documentation updates
  `#909 <https://github.com/libgit2/pygit2/pull/909>`_

- Test updates
  `#911 <https://github.com/libgit2/pygit2/pull/911>`_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants