pyldb: avoid segfault when adding an element with no name
[nivanova/samba-autobuild/.git] / lib / ldb / pyldb.c
index 6e845d15c36cf56a3e9eeecc2b4decda1e529483..319840c2ea654ccb000a3afc3a73c1cfd504c36a 100644 (file)
@@ -3528,7 +3528,11 @@ static PyObject *py_ldb_msg_add(PyLdbMessageObject *self, PyObject *args)
                PyErr_SetString(PyExc_ValueError, "Invalid MessageElement object");
                return NULL;
        }
                PyErr_SetString(PyExc_ValueError, "Invalid MessageElement object");
                return NULL;
        }
-
+       if (el->name == NULL) {
+               PyErr_SetString(PyExc_ValueError,
+                               "The element has no name");
+               return NULL;
+       }
        ret = ldb_msg_add_empty(msg, el->name, el->flags, &el_new);
        PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, NULL);
 
        ret = ldb_msg_add_empty(msg, el->name, el->flags, &el_new);
        PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, NULL);