pyldb: avoid segfault when adding an element with no name master origin/HEAD origin/master
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 12 Apr 2019 03:00:20 +0000 (15:00 +1200)
committerNoel Power <npower@samba.org>
Tue, 23 Apr 2019 19:03:35 +0000 (19:03 +0000)
We don't want to see this:

python3 -c "import sys
sys.path.insert(0, 'bin/python')
import ldb
m = ldb.Message()
e = ldb.MessageElement('q')
try:
    m.add(e)
except ldb.LdbError:
    pass
print(m)
"
Segmentation fault (core dumped)

instead we want this:

Traceback (most recent call last):
File "<string>", line 7, in <module>
ValueError: The element has no name

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Noel Power <npower@samba.org>
Autobuild-User(master): Noel Power <npower@samba.org>
Autobuild-Date(master): Tue Apr 23 19:03:35 UTC 2019 on sn-devel-144

lib/ldb/pyldb.c
selftest/knownfail.d/python-segfaults

index 6e845d1..319840c 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;
        }
-
+       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);
 
index bc2a716..c8331d9 100644 (file)
@@ -4,4 +4,3 @@ samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_hive_open_ldb
 samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_net_replicate_chunk_1
 samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_net_replicate_init__1
 samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_net_replicate_init__3
-samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_ldb_add_nameless_element