Author: henry Date: Fri Apr 30 22:50:13 2010 New Revision: 939866 URL: http://svn.apache.org/viewvc?rev=939866&view=rev Log: ZOOKEEPER-758. zkpython segfaults on invalid acl with missing key
Modified: hadoop/zookeeper/trunk/CHANGES.txt hadoop/zookeeper/trunk/src/contrib/zkpython/src/c/zookeeper.c hadoop/zookeeper/trunk/src/contrib/zkpython/src/test/acl_test.py Modified: hadoop/zookeeper/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=939866&r1=939865&r2=939866&view=diff ============================================================================== --- hadoop/zookeeper/trunk/CHANGES.txt (original) +++ hadoop/zookeeper/trunk/CHANGES.txt Fri Apr 30 22:50:13 2010 @@ -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) Modified: hadoop/zookeeper/trunk/src/contrib/zkpython/src/c/zookeeper.c URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zkpython/src/c/zookeeper.c?rev=939866&r1=939865&r2=939866&view=diff ============================================================================== --- hadoop/zookeeper/trunk/src/contrib/zkpython/src/c/zookeeper.c (original) +++ hadoop/zookeeper/trunk/src/contrib/zkpython/src/c/zookeeper.c Fri Apr 30 22:50:13 2010 @@ -286,8 +286,9 @@ PyObject *build_string_vector(const stru /* 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; } Modified: hadoop/zookeeper/trunk/src/contrib/zkpython/src/test/acl_test.py URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zkpython/src/test/acl_test.py?rev=939866&r1=939865&r2=939866&view=diff ============================================================================== --- hadoop/zookeeper/trunk/src/contrib/zkpython/src/test/acl_test.py (original) +++ hadoop/zookeeper/trunk/src/contrib/zkpython/src/test/acl_test.py Fri Apr 30 22:50:13 2010 @@ -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()