You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ma...@apache.org on 2011/12/08 22:58:28 UTC

svn commit: r1212153 - in /zookeeper/trunk: CHANGES.txt src/c/src/zookeeper.c src/c/tests/TestClient.cc

Author: mahadev
Date: Thu Dec  8 21:58:28 2011
New Revision: 1212153

URL: http://svn.apache.org/viewvc?rev=1212153&view=rev
Log:
ZOOKEEPER-1305. zookeeper.c:prepend_string func can dereference null ptr. (Daniel Lescohier via mahadev)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/c/src/zookeeper.c
    zookeeper/trunk/src/c/tests/TestClient.cc

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1212153&r1=1212152&r2=1212153&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Thu Dec  8 21:58:28 2011
@@ -59,7 +59,10 @@ BUGFIXES:
   ZOOKEEPER-1239. add logging/stats to identify fsync stalls. (phunt via camille)
 
   ZOOKEEPER-1311. ZooKeeper test jar is broken (Ivan Kelly via phunt)
-   
+ 
+  ZOOKEEPER-1305. zookeeper.c:prepend_string func can dereference null ptr. 
+  (Daniel Lescohier via mahadev)
+ 
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

Modified: zookeeper/trunk/src/c/src/zookeeper.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/zookeeper.c?rev=1212153&r1=1212152&r2=1212153&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/zookeeper.c (original)
+++ zookeeper/trunk/src/c/src/zookeeper.c Thu Dec  8 21:58:28 2011
@@ -871,7 +871,7 @@ void free_duplicate_path(const char *fre
 */
 static char* prepend_string(zhandle_t *zh, const char* client_path) {
     char *ret_str;
-    if (zh->chroot == NULL)
+    if (zh == NULL || zh->chroot == NULL)
         return (char *) client_path;
     // handle the chroot itself, client_path = "/"
     if (strlen(client_path) == 1) {

Modified: zookeeper/trunk/src/c/tests/TestClient.cc
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/tests/TestClient.cc?rev=1212153&r1=1212152&r2=1212153&view=diff
==============================================================================
--- zookeeper/trunk/src/c/tests/TestClient.cc (original)
+++ zookeeper/trunk/src/c/tests/TestClient.cc Thu Dec  8 21:58:28 2011
@@ -792,6 +792,10 @@ public:
         zk_ch = createchClient(&ctx_ch, "127.0.0.1:22181/testch1/mahadev");
         CPPUNIT_ASSERT(zk_ch != NULL);
         zk = createClient(&ctx);
+        // first test with a NULL zk handle, make sure client library does not
+        // dereference a null pointer, but instead returns ZBADARGUMENTS
+        rc = zoo_create(NULL, "/testch1", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
+        CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
         rc = zoo_create(zk, "/testch1", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         rc = zoo_create(zk, "/testch1/mahadev", data, 7, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);