tag._message: avoid NULL pointer dereference

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.
This commit is contained in:
Nicolas Dandrimont
2015-10-05 19:08:56 +02:00
parent 2b083a1509
commit eadc2a320f

View File

@@ -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[] = {