Skip to content

Commit

Permalink
talloc: add pytalloc_get_name() helper
Browse files Browse the repository at this point in the history
In several places we go

   talloc_get_name(pytalloc_get_ptr(py_obj))

which is a certain NULL derefernce if py_obj is not a talloc object.

This is a helper function that chooses to say "non-talloc object"
rather than crash.

Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Gary Lockyer <[email protected]>
Reviewed-by: Andrew Bartlett <[email protected]>
  • Loading branch information
douglasbagnall authored and abartlet committed Jul 22, 2019
1 parent 3383390 commit 4496e07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/talloc/pytalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ void *_pytalloc_get_ptr(PyObject *py_obj);
TALLOC_CTX *_pytalloc_get_mem_ctx(PyObject *py_obj);
#define pytalloc_get_mem_ctx(py_obj) _pytalloc_get_mem_ctx((PyObject *)(py_obj))

const char *_pytalloc_get_name(PyObject *py_obj);
#define pytalloc_get_name(py_obj) _pytalloc_get_name((PyObject *)(py_obj))


PyObject *pytalloc_steal_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
PyObject *pytalloc_steal(PyTypeObject *py_type, void *ptr);
PyObject *pytalloc_reference_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
Expand Down
9 changes: 9 additions & 0 deletions lib/talloc/pytalloc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,12 @@ _PUBLIC_ int pytalloc_BaseObject_PyType_Ready(PyTypeObject *type)

return PyType_Ready(type);
}

_PUBLIC_ const char *_pytalloc_get_name(PyObject *obj)
{
void *ptr = pytalloc_get_ptr(obj);
if (ptr == NULL) {
return "non-talloc object";
}
return talloc_get_name(ptr);
}

0 comments on commit 4496e07

Please sign in to comment.