Skip to content

Commit

Permalink
tag._message: avoid NULL pointer dereference
Browse files Browse the repository at this point in the history
A tag message can be empty. In that case, git_tag_message returns
NULL. PyBytes_FromString doesn't check its argument for nullness, and
therefore accessing _message on a tag with an empty message segfaults
Python.
  • Loading branch information
olasd committed Oct 5, 2015
1 parent 2b083a1 commit eadc2a3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ PyDoc_STRVAR(Tag__message__doc__, "Tag message (bytes).");
PyObject *
Tag__message__get__(Tag *self)
{
return PyBytes_FromString(git_tag_message(self->tag));
const char *message;
message = git_tag_message(self->tag);
if (!message)
Py_RETURN_NONE;
return PyBytes_FromString(message);
}

PyMethodDef Tag_methods[] = {
Expand Down

0 comments on commit eadc2a3

Please sign in to comment.