Explorar o código

ZOOKEEPER-624. The C Client cause core dump when receive error data from Zookeeper Server (mahadev)

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

+ 3 - 0
CHANGES.txt

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

+ 3 - 0
src/c/src/recordio.c

@@ -263,6 +263,9 @@ int ia_deserialize_string(struct iarchive *ia, const char *name, char **s)
     if ((priv->len - priv->off) < len) {
         return -E2BIG;
     }
+    if (len < 0) {
+        return -EINVAL;
+    }
     *s = malloc(len+1);
     if (!*s) {
         return -ENOMEM;

+ 23 - 1
src/c/tests/TestClient.cc

@@ -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 CPPUNIT_NS::TestFixture
 {
     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;