From: Douglas Bagnall Date: Fri, 13 Apr 2018 00:29:05 +0000 (+1200) Subject: python.gpo.ADS_STRUCT: check type of loadparm argument X-Git-Tag: ldb-1.4.0~461 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b3d3304e5a55dbc4353ddade82da43e079e33ed;p=thirdparty%2Fsamba.git python.gpo.ADS_STRUCT: check type of loadparm argument And add a test showning the segfault. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c index db336021125..60220a6bc2a 100644 --- a/libgpo/pygpo.c +++ b/libgpo/pygpo.c @@ -183,7 +183,14 @@ static int py_ads_init(ADS *self, PyObject *args, PyObject *kwds) } if (lp_obj) { - bool ok; + bool ok = py_check_dcerpc_type(lp_obj, "samba.param", + "LoadParm"); + if (!ok) { + PyErr_Format(PyExc_TypeError, + "Expected samba.param.LoadParm " + "for lp argument"); + return -1; + } lp_ctx = pytalloc_get_type(lp_obj, struct loadparm_context); if (lp_ctx == NULL) { return -1; diff --git a/python/samba/tests/gpo.py b/python/samba/tests/gpo.py index bdcbcc6c754..796a5cb06cb 100644 --- a/python/samba/tests/gpo.py +++ b/python/samba/tests/gpo.py @@ -50,6 +50,13 @@ class GPOTests(tests.TestCase): assert gpos[i].ds_path == ds_paths[i], \ 'ds_path did not match expected %s' % gpos[i].ds_path + + def test_gpo_ads_does_not_segfault(self): + try: + ads = gpo.ADS_STRUCT(self.server, 42, self.creds) + except: + pass + def test_gpt_version(self): global gpt_data local_path = self.lp.get("path", "sysvol")