Author: mahadev
Date: Wed Mar 17 00:05:24 2010
New Revision: 924065

URL: http://svn.apache.org/viewvc?rev=924065&view=rev
Log:
ZOOKEEPER-624. The C Client cause core dump when receive error data from 
Zookeeper Server (mahadev)

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

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=924065&r1=924064&r2=924065&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Wed Mar 17 00:05:24 2010
@@ -290,6 +290,9 @@ BUGFIXES: 
 
   ZOOKEEPER-586. c client does not compile under cygwin (phunt, mahadev, breed 
via breed)
 
+  ZOOKEEPER-624. The C Client cause core dump when receive error data from
+  Zookeeper Server (mahadev)
+
 IMPROVEMENTS:
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   "socket reuse" and failure to close client (phunt via mahadev)

Modified: hadoop/zookeeper/trunk/src/c/src/recordio.c
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/src/recordio.c?rev=924065&r1=924064&r2=924065&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/src/recordio.c (original)
+++ hadoop/zookeeper/trunk/src/c/src/recordio.c Wed Mar 17 00:05:24 2010
@@ -263,6 +263,9 @@ int ia_deserialize_string(struct iarchiv
     if ((priv->len - priv->off) < len) {
         return -E2BIG;
     }
+    if (len < 0) {
+        return -EINVAL;
+    }
     *s = malloc(len+1);
     if (!*s) {
         return -ENOMEM;

Modified: hadoop/zookeeper/trunk/src/c/tests/TestClient.cc
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/tests/TestClient.cc?rev=924065&r1=924064&r2=924065&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/tests/TestClient.cc (original)
+++ hadoop/zookeeper/trunk/src/c/tests/TestClient.cc Wed Mar 17 00:05:24 2010
@@ -36,9 +36,16 @@ using namespace std;
 #include <list>
 
 #include <zookeeper.h>
-
+#include <errno.h>
+#include <recordio.h>
 #include "Util.h"
 
+struct buff_struct_2 {
+    int32_t len;
+    int32_t off;
+    char *buffer;
+};
+
 static int Stat_eq(struct Stat* a, struct Stat* b)
 {
     if (a->czxid != b->czxid) return 0;
@@ -178,6 +185,7 @@ class Zookeeper_simpleSystem : public CP
 {
     CPPUNIT_TEST_SUITE(Zookeeper_simpleSystem);
     CPPUNIT_TEST(testAsyncWatcherAutoReset);
+    CPPUNIT_TEST(testDeserializeString);
 #ifdef THREADED
     CPPUNIT_TEST(testNullData);
     CPPUNIT_TEST(testIPV6);
@@ -428,6 +436,20 @@ public:
         return true;
     }
 
+    void testDeserializeString() {
+        char *val_str;
+        int rc = 0;
+        int val = -1;
+        struct iarchive *ia;
+        struct buff_struct_2 *b;
+        struct oarchive *oa = create_buffer_oarchive();
+        oa->serialize_Int(oa, "int", &val);
+        b = (struct buff_struct_2 *) oa->priv;
+        ia = create_buffer_iarchive(b->buffer, b->len);
+        rc = ia->deserialize_String(ia, "string", &val_str);
+        CPPUNIT_ASSERT_EQUAL(-EINVAL, rc);
+    }
+        
     void testAcl() {
         int rc;
         struct ACL_vector aclvec;


Reply via email to