From 57f69e6f37949636ae14c646517792fa40c9c75b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 10 Feb 2005 03:19:21 +0000 Subject: r5293: Map an empty policy handle to None when creating policy handles, and refuse to accept None as a policy handle when accepting them. Now we don't segfault after running the samr_Shutdown() test. (This used to be commit 2f0419c4d8100864ddddf5629d1808b655da9d76) --- source4/scripting/swig/dcerpc.i | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'source4/scripting/swig') diff --git a/source4/scripting/swig/dcerpc.i b/source4/scripting/swig/dcerpc.i index 471140c499..3d9d076e58 100644 --- a/source4/scripting/swig/dcerpc.i +++ b/source4/scripting/swig/dcerpc.i @@ -182,14 +182,31 @@ const char *dcerpc_server_name(struct dcerpc_pipe *p); $result = PyLong_FromLong(*$1); } +%typemap(in) struct policy_handle * { + + if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, + SWIG_POINTER_EXCEPTION)) == -1) + return NULL; + + if ($1 == NULL) { + PyErr_SetString(PyExc_TypeError, "None is not a valid policy handle"); + return NULL; + } +} + /* When returning a policy handle to Python we need to make a copy of as the talloc context it is created under is destroyed after the wrapper function returns. TODO: Fix memory leak created here. */ %typemap(out) struct policy_handle * { - struct policy_handle *temp = (struct policy_handle *)malloc(sizeof(struct policy_handle)); - memcpy(temp, $1, sizeof(struct policy_handle)); - $result = SWIG_NewPointerObj(temp, SWIGTYPE_p_policy_handle, 0); + if ($1) { + struct policy_handle *temp = (struct policy_handle *)malloc(sizeof(struct policy_handle)); + memcpy(temp, $1, sizeof(struct policy_handle)); + $result = SWIG_NewPointerObj(temp, SWIGTYPE_p_policy_handle, 0); + } else { + Py_INCREF(Py_None); + $result = Py_None; + } } %{ -- cgit