Browse Source

ZOOKEEPER-758. zkpython segfaults on invalid acl with missing key

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@939866 13f79535-47bb-0310-9956-ffa450edef68
Henry Robinson 15 years ago
parent
commit
dd8f018c05
3 changed files with 42 additions and 2 deletions
  1. 3 0
      CHANGES.txt
  2. 19 2
      src/contrib/zkpython/src/c/zookeeper.c
  3. 20 0
      src/contrib/zkpython/src/test/acl_test.py

+ 3 - 0
CHANGES.txt

@@ -41,6 +41,9 @@ BUGFIXES:
   ZOOKEEPER-750. move maven artifacts into "dist-maven" subdir of the
   release (package target) (phunt via henryr)
 
+  ZOOKEEPER-758. zkpython segfaults on invalid acl with missing key
+  (Kapil Thangavelu via henryr)
+
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 
   (phunt via mahadev)

+ 19 - 2
src/contrib/zkpython/src/c/zookeeper.c

@@ -286,8 +286,9 @@ PyObject *build_string_vector(const struct String_vector *sv)
 
 /* Returns 1 if the PyObject is a valid representation of an ACL, and
    0 otherwise. */
-int check_is_acl(PyObject *o) { 
+int check_is_acl(PyObject *o) {
   int i;
+  PyObject *entry;
   if (o == NULL) {
     return 0;
   }
@@ -295,10 +296,26 @@ int check_is_acl(PyObject *o) {
     return 0;
   }
   for (i=0;i<PyList_Size(o);++i) {
-    if (!PyDict_Check(PyList_GetItem(o,i))) {
+    PyObject *element = PyList_GetItem(o,i);
+    if (!PyDict_Check(element)) {
+      return 0;
+    }
+    entry = PyDict_GetItemString( element, "perms" );
+    if (entry == Py_None) {
+      return 0;
+    }
+
+    entry = PyDict_GetItemString( element, "scheme" );
+    if (entry == Py_None) {
+      return 0;
+    }
+
+    entry = PyDict_GetItemString( element, "id" );
+    if (entry == Py_None) {
       return 0;
     }
   }
+
   return 1;
 }
 

+ 20 - 0
src/contrib/zkpython/src/test/acl_test.py

@@ -85,5 +85,25 @@ class ACLTest(zktestbase.TestBase):
       acls = zookeeper.get_acl(self.handle, "/zk-python-aacltest")
       self.assertEqual(acls[1], [ZOO_ACL_READ], "Wrong ACL returned from get when aset")
 
+    def test_invalid_acl(self):
+      self.assertRaises(zookeeper.InvalidACLException,
+                        zookeeper.create,
+                        self.handle,
+                        "/zk-python-aclverifytest",
+                        "",
+                        None,
+                        zookeeper.EPHEMERAL)
+      
+    def test_invalid_acl2(self):
+      """Verify all required keys are present in the ACL."""
+      invalid_acl = [{"schema": "digest", "id": "zebra"}],
+      self.assertRaises(zookeeper.InvalidACLException,
+                        zookeeper.create,
+                        self.handle,
+                        "/zk-python-aclverifytest",
+                        "",
+                        invalid_acl,
+                        zookeeper.EPHEMERAL))
+
 if __name__ == '__main__':
     unittest.main()