pyldb: do type checking on the list form of ldb add
authorAndrew Tridgell <tridge@samba.org>
Sun, 22 Aug 2010 04:50:22 +0000 (14:50 +1000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 22 Aug 2010 04:57:34 +0000 (14:57 +1000)
Pair-Programmed-With: Jelmer Vernooij <jelmer@samba.org>

source4/lib/ldb/pyldb.c

index 19123c3c249347f71f3637e4bd40906b31a982ec..f1b73a96fb79e68aa843b43b14ce85a09d5558a0 100644 (file)
@@ -1691,6 +1691,12 @@ struct ldb_message_element *PyObject_AsMessageElement(TALLOC_CTX *mem_ctx,
                me->values = talloc_array(me, struct ldb_val, me->num_values);
                for (i = 0; i < me->num_values; i++) {
                        PyObject *obj = PySequence_GetItem(set_obj, i);
+                       if (!PyString_Check(obj)) {
+                               PyErr_Format(PyExc_TypeError,
+                                            "Expected string as element %d in list", i);
+                               talloc_free(me);
+                               return NULL;
+                       }
 
                        me->values[i].length = PyString_Size(obj);
                        me->values[i].data = talloc_memdup(me,