s4/py_dsdb: avoid NULL deref in set_domain_sid()
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 4 Jul 2019 10:21:36 +0000 (22:21 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 22 Jul 2019 22:20:25 +0000 (22:20 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/pydsdb.c

index de459388a1844b267966b947b5da3f62efc7f227..f173a35599775ea40e09d0e699315f50df716fb8 100644 (file)
@@ -129,18 +129,25 @@ static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
 }
 
 static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
-{ 
+{
        PyObject *py_ldb, *py_sid;
        struct ldb_context *ldb;
        struct dom_sid *sid;
        bool ret;
+       const char *sid_str = NULL;
 
        if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_sid))
                return NULL;
-       
+
        PyErr_LDB_OR_RAISE(py_ldb, ldb);
 
-       sid = dom_sid_parse_talloc(NULL, PyUnicode_AsUTF8(py_sid));
+       sid_str = PyUnicode_AsUTF8(py_sid);
+       if (sid_str == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       sid = dom_sid_parse_talloc(NULL, sid_str);
        if (sid == NULL) {
                PyErr_NoMemory();
                return NULL;