[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Mon Nov 24 23:25:02 MST 2014


The branch, master has been updated
       via  30c0790 lib-pyldb: Block elements should be surrounded by {} in py_msg.setitem()
       via  3223208 lib-pyldb: Fix docstring for msg.add() method - it was "S.append()"
       via  1d14af7 lib-ldb-test: Test copying message element from a message to a new message
       via  2d67335 lib-pyldb: Avoid crash when copying MessageElements between Python Message objects
       via  7f121d3 lib-ldb_ldif: Stop processing if ldb_message element name is NULL
       via  ea77786 lib-ldb: Check for input parameter when searching attributes by name
       via  4d25dfd lib-pyldb: Throw exception when we can't create MessageElement object
       via  18f879b lib-pyldb: Avoid leaking memory in error cases
       via  a48b533 lib-pyldb: Avoid SEGFAULT in case we can't convert passed value to py_String
      from  0d5adad s3-smbstatus: Fix exit code of profile output.

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 30c07907749063d0b0c663f1b43b02b4c6b0049d
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Thu Nov 20 04:07:47 2014 +0100

    lib-pyldb: Block elements should be surrounded by {} in py_msg.setitem()
    
    Change-Id: I0d09374b27708fcaad3523d985a2db7983dbd81a
    Signed-off-by: Kamen Mazdrashki <kamenim at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Tue Nov 25 07:24:12 CET 2014 on sn-devel-104

commit 322320889c60f31cc536342bc9a54ae258f41139
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Thu Nov 20 04:06:01 2014 +0100

    lib-pyldb: Fix docstring for msg.add() method - it was "S.append()"
    
    Change-Id: I9492d3c3993fc3d68d7bf24405db6e8cd746eaac
    Signed-off-by: Kamen Mazdrashki <kamenim at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 1d14af77299e88b5f0d3230ec0481ed5abaf4bdd
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Tue Nov 25 03:50:52 2014 +0100

    lib-ldb-test: Test copying message element from a message to a new message
    
    Change-Id: Iefcafb418a170ee410aec900bb36eb8e01e946b1
    Signed-off-by: Kamen Mazdrashki <kamenim at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 2d67335f681a60a636e48107d908778806a0b15f
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Nov 12 01:17:56 2014 +0100

    lib-pyldb: Avoid crash when copying MessageElements between Python Message objects
    
    This patch allows for following snipets in Python:
      res = ldb.search(...)
      m_from = res[0]
      m_to = Message()
      m_to.add(m_from["attrName"])
    
    The problem previously is that we are trying to reference a
    ldb_message_element that may not be a memory context on its own.
    For instance, when search request from above example returns
    Messages with more than one attribute, this leads immediately
    to "Bad talloc magic value" crash, every message element beside
    the first one is not a memory context
    
    Signed-off-by: Kamen Mazdrashki <kamenim at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 7f121d3860ee3289f5fd397ab3312634d11cb2f2
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Nov 12 01:12:31 2014 +0100

    lib-ldb_ldif: Stop processing if ldb_message element name is NULL
    
    I have hit this while using Python bindings for testing and
    forgot to pass 'name' argument to MessageElement constructor
    Passing NULL as 'name' is obviously a mistake and this commits
    aims to warn about such unintetional mistakes.
    
    Signed-off-by: Kamen Mazdrashki <kamenim at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit ea7778697e22ffbe22634974144c6e5c142a85d6
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Tue Nov 11 02:56:32 2014 +0100

    lib-ldb: Check for input parameter when searching attributes by name
    
    This prevents a segfault that is hard to be tracked down from
    Python bindings for instance.
    
    Signed-off-by: Kamen Mazdrashki <kamenim at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 4d25dfd611e7786a17975fcaed039be971bac7da
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Mon Nov 10 22:59:07 2014 +0100

    lib-pyldb: Throw exception when we can't create MessageElement object
    
    At the moment we return an error, but no exception and it is
    hard to instantly see what the problem is from Python
    
    Signed-off-by: Kamen Mazdrashki <kamenim at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 18f879b857c174371a9fe27722c70051ed68ed64
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Sun Nov 9 04:31:36 2014 +0100

    lib-pyldb: Avoid leaking memory in error cases
    
    Signed-off-by: Kamen Mazdrashki <kamenim at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit a48b533ea5c9faae3429b0fb680b52b14676cd22
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Sun Nov 9 04:28:47 2014 +0100

    lib-pyldb: Avoid SEGFAULT in case we can't convert passed value to py_String
    
    Signed-off-by: Kamen Mazdrashki <kamenim at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/ldb/common/ldb_attributes.c | 15 ++++++++++++--
 lib/ldb/common/ldb_ldif.c       |  7 +++++++
 lib/ldb/pyldb.c                 | 46 ++++++++++++++++++++++++++++++++++-------
 lib/ldb/tests/python/api.py     | 14 +++++++++++++
 4 files changed, 72 insertions(+), 10 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/ldb/common/ldb_attributes.c b/lib/ldb/common/ldb_attributes.c
index 21a3e6e..767f69c 100644
--- a/lib/ldb/common/ldb_attributes.c
+++ b/lib/ldb/common/ldb_attributes.c
@@ -116,8 +116,14 @@ static const struct ldb_schema_attribute ldb_attribute_default = {
 };
 
 /*
-  return the attribute handlers for a given attribute
-*/
+ * Return the attribute handlers for a given attribute
+ *
+ * @param ldb	ldb context
+ * @param name	attribute name to search for
+ * @return	Always return valid pointer to schema attribute.
+ * 		In case there is no attribute with name,
+ * 		ldb_attribute_default is returned
+ */
 static const struct ldb_schema_attribute *ldb_schema_attribute_by_name_internal(
 	struct ldb_context *ldb,
 	const char *name)
@@ -127,6 +133,11 @@ static const struct ldb_schema_attribute *ldb_schema_attribute_by_name_internal(
 	int r;
 	const struct ldb_schema_attribute *def = &ldb_attribute_default;
 
+	/* fallback to default attribute implementation */
+	if (name == NULL) {
+		return def;
+	}
+
 	/* as handlers are sorted, '*' must be the first if present */
 	if (strcmp(ldb->schema.attributes[0].name, "*") == 0) {
 		def = &ldb->schema.attributes[0];
diff --git a/lib/ldb/common/ldb_ldif.c b/lib/ldb/common/ldb_ldif.c
index a2e4488..f9743dc 100644
--- a/lib/ldb/common/ldb_ldif.c
+++ b/lib/ldb/common/ldb_ldif.c
@@ -312,6 +312,13 @@ static int ldb_ldif_write_trace(struct ldb_context *ldb,
 	for (i=0;i<msg->num_elements;i++) {
 		const struct ldb_schema_attribute *a;
 
+		if (msg->elements[i].name == NULL) {
+			ldb_debug(ldb, LDB_DEBUG_ERROR,
+					"Error: Invalid element name (NULL) at position %d", i);
+			talloc_free(mem_ctx);
+			return -1;
+		}
+
 		a = ldb_schema_attribute_by_name(ldb, msg->elements[i].name);
 
 		if (ldif->changetype == LDB_CHANGETYPE_MODIFY) {
diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c
index 78b8012..ee751b3 100644
--- a/lib/ldb/pyldb.c
+++ b/lib/ldb/pyldb.c
@@ -1624,17 +1624,26 @@ static PyObject *py_ldb_schema_format_value(PyLdbObject *self, PyObject *args)
 	if (!PyArg_ParseTuple(args, "sO", &element_name, &val))
 		return NULL;
 
-	mem_ctx = talloc_new(NULL);
-
 	old_val.data = (uint8_t *)PyString_AsString(val);
 	old_val.length = PyString_Size(val);
 
+	if (old_val.data == NULL) {
+		PyErr_SetString(PyExc_RuntimeError, "Failed to convert passed value to String");
+		return NULL;
+	}
+
 	a = ldb_schema_attribute_by_name(pyldb_Ldb_AsLdbContext(self), element_name);
 
 	if (a == NULL) {
 		Py_RETURN_NONE;
 	}
 
+	mem_ctx = talloc_new(NULL);
+	if (mem_ctx == NULL) {
+		PyErr_NoMemory();
+		return NULL;
+	}
+
 	if (a->syntax->ldif_write_fn(pyldb_Ldb_AsLdbContext(self), mem_ctx, &old_val, &new_val) != 0) {
 		talloc_free(mem_ctx);
 		Py_RETURN_NONE;
@@ -2343,6 +2352,8 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 				(uint8_t *)PyString_AsString(obj), me->values[i].length+1);
 		}
 	} else {
+		PyErr_Format(PyExc_TypeError,
+			     "String or List type expected for '%s' attribute", attr_name);
 		talloc_free(me);
 		me = NULL;
 	}
@@ -2764,21 +2775,39 @@ static PyObject *py_ldb_msg_add(PyLdbMessageObject *self, PyObject *args)
 {
 	struct ldb_message *msg = pyldb_Message_AsMessage(self);
 	PyLdbMessageElementObject *py_element;
-	int ret;
+	int i, ret;
 	struct ldb_message_element *el;
+	struct ldb_message_element *el_new;
 
 	if (!PyArg_ParseTuple(args, "O!", &PyLdbMessageElement, &py_element))
 		return NULL;
 
-	el = talloc_reference(msg, py_element->el);
+	el = py_element->el;
 	if (el == NULL) {
-		PyErr_NoMemory();
+		PyErr_SetString(PyExc_ValueError, "Invalid MessageElement object");
 		return NULL;
 	}
 
-	ret = ldb_msg_add(msg, el, el->flags);
+	ret = ldb_msg_add_empty(msg, el->name, el->flags, &el_new);
 	PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, NULL);
 
+	/* now deep copy all attribute values */
+	el_new->values = talloc_array(msg->elements, struct ldb_val, el->num_values);
+	if (el_new->values == NULL) {
+		PyErr_NoMemory();
+		return NULL;
+	}
+	el_new->num_values = el->num_values;
+
+	for (i = 0; i < el->num_values; i++) {
+		el_new->values[i] = ldb_val_dup(el_new->values, &el->values[i]);
+		if (el_new->values[i].data == NULL
+				&& el->values[i].length != 0) {
+			PyErr_NoMemory();
+			return NULL;
+		}
+	}
+
 	Py_RETURN_NONE;
 }
 
@@ -2802,7 +2831,7 @@ static PyMethodDef py_ldb_msg_methods[] = {
 	{ "items", (PyCFunction)py_ldb_msg_items, METH_NOARGS, NULL },
 	{ "elements", (PyCFunction)py_ldb_msg_elements, METH_NOARGS, NULL },
 	{ "add", (PyCFunction)py_ldb_msg_add, METH_VARARGS,
-		"S.append(element)\n\n"
+		"S.add(element)\n\n"
 		"Add an element to this message." },
 	{ NULL },
 };
@@ -2834,8 +2863,9 @@ static int py_ldb_msg_setitem(PyLdbMessageObject *self, PyObject *name, PyObject
 		int ret;
 		struct ldb_message_element *el = PyObject_AsMessageElement(self->msg,
 									   value, 0, attr_name);
-		if (el == NULL)
+		if (el == NULL) {
 			return -1;
+		}
 		ldb_msg_remove_attr(pyldb_Message_AsMessage(self), attr_name);
 		ret = ldb_msg_add(pyldb_Message_AsMessage(self), el, el->flags);
 		if (ret != LDB_SUCCESS) {
diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py
index 7df40e4..7f5c504 100755
--- a/lib/ldb/tests/python/api.py
+++ b/lib/ldb/tests/python/api.py
@@ -592,6 +592,20 @@ class LdbMsgTests(TestCase):
         err_rec = {"a1": ["a1-val1", "a1-val1"]}
         self.assertRaises(TypeError, ldb.Message.from_dict, l, err_rec, ldb.FLAG_MOD_REPLACE)
 
+    def test_copy_add_message_element(self):
+        m = ldb.Message()
+        m["1"] = ldb.MessageElement(["val 111"], ldb.FLAG_MOD_ADD, "1")
+        m["2"] = ldb.MessageElement(["val 222"], ldb.FLAG_MOD_ADD, "2")
+        mto = ldb.Message()
+        mto["1"] = m["1"]
+        mto["2"] = m["2"]
+        self.assertEqual(mto["1"], m["1"])
+        self.assertEqual(mto["2"], m["2"])
+        mto = ldb.Message()
+        mto.add(m["1"])
+        mto.add(m["2"])
+        self.assertEqual(mto["1"], m["1"])
+        self.assertEqual(mto["2"], m["2"])
 
 
 class MessageElementTests(TestCase):


-- 
Samba Shared Repository


More information about the samba-cvs mailing list