Explorar o código

ZOOKEEPER-1305. zookeeper.c:prepend_string func can dereference null ptr. (Daniel Lescohier via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1212153 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar %!s(int64=13) %!d(string=hai) anos
pai
achega
9553f94271
Modificáronse 3 ficheiros con 9 adicións e 2 borrados
  1. 4 1
      CHANGES.txt
  2. 1 1
      src/c/src/zookeeper.c
  3. 4 0
      src/c/tests/TestClient.cc

+ 4 - 1
CHANGES.txt

@@ -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,

+ 1 - 1
src/c/src/zookeeper.c

@@ -871,7 +871,7 @@ void free_duplicate_path(const char *free_path, const char* path) {
 */
 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) {

+ 4 - 0
src/c/tests/TestClient.cc

@@ -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);