Skip to content

Commit

Permalink
Fix Potential Nullptr Dereference
Browse files Browse the repository at this point in the history
Fix a potential nullptr dereference of `obj`.

Found with coverity in a downstream project.
  • Loading branch information
ax3l committed Jan 7, 2019
1 parent 085a294 commit d538bec
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/pybind11/detail/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {

/// buffer_protocol: Fill in the view as specified by flags.
extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int flags) {
if (obj == nullptr) {
PyErr_SetString(PyExc_BufferError, "pybind11_getbuffer(): Internal error (PyObject is nullptr)");
return -1;
}
// Look for a `get_buffer` implementation in this type's info or any bases (following MRO).
type_info *tinfo = nullptr;
for (auto type : reinterpret_borrow<tuple>(Py_TYPE(obj)->tp_mro)) {
Expand Down

0 comments on commit d538bec

Please sign in to comment.