You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2019/04/01 14:45:28 UTC

[geode-native] branch develop updated: GEODE-6491: Fix signed/unsigned problem reading size field in handshake message (#468)

This is an automated email from the ASF dual-hosted git repository.

jbarrett pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 3430ae4  GEODE-6491: Fix signed/unsigned problem reading size field in handshake message (#468)
3430ae4 is described below

commit 3430ae41d72a6e3fe5b3b8a6a6ea440887c67fcf
Author: Blake Bender <ek...@hotmail.com>
AuthorDate: Mon Apr 1 07:45:23 2019 -0700

    GEODE-6491: Fix signed/unsigned problem reading size field in handshake message (#468)
    
    Co-Authored-By: Jacob Barrett <jb...@pivotal.io>
---
 cppcache/src/SerializationRegistry.cpp |  6 ++--
 cppcache/src/TcrConnection.cpp         | 66 ++++++++++------------------------
 cppcache/src/TcrConnection.hpp         |  2 +-
 3 files changed, 23 insertions(+), 51 deletions(-)

diff --git a/cppcache/src/SerializationRegistry.cpp b/cppcache/src/SerializationRegistry.cpp
index 7918144..b7d5e71 100644
--- a/cppcache/src/SerializationRegistry.cpp
+++ b/cppcache/src/SerializationRegistry.cpp
@@ -158,9 +158,9 @@ std::shared_ptr<Serializable> SerializationRegistry::deserialize(
     dsCode = static_cast<DSCode>(input.read());
   }
 
-  LOGDEBUG(
-      "SerializationRegistry::deserialize typeid = %d currentTypeId= %" PRId8,
-      typeId, dsCode);
+  LOGDEBUG("SerializationRegistry::deserialize typeId = %" PRId8
+           " dsCode = % " PRId8,
+           typeId, dsCode);
 
   switch (dsCode) {
     case DSCode::CacheableNullString: {
diff --git a/cppcache/src/TcrConnection.cpp b/cppcache/src/TcrConnection.cpp
index 21ac8b4..b38bc25 100644
--- a/cppcache/src/TcrConnection.cpp
+++ b/cppcache/src/TcrConnection.cpp
@@ -428,23 +428,8 @@ bool TcrConnection::InitTcrConnection(
     }
 
     if (!isClientNotification) {
-      // Read and ignore the DistributedMember object
-      auto arrayLenHeader = readHandshakeData(1, connectTimeout);
-      int32_t recvMsgLen = static_cast<int32_t>(arrayLenHeader[0]);
-      // now check for array length headers - since GFE 5.7
-      if (static_cast<int8_t>(arrayLenHeader[0]) == -2) {
-        auto recvMsgLenBytes = readHandshakeData(2, connectTimeout);
-        auto dataInput2 = m_connectionManager->getCacheImpl()->createDataInput(
-            reinterpret_cast<const uint8_t*>(recvMsgLenBytes.data()),
-            recvMsgLenBytes.size());
-        recvMsgLen = dataInput2.readInt16();
-      } else if (static_cast<int8_t>(arrayLenHeader[0]) == -3) {
-        auto recvMsgLenBytes = readHandshakeData(4, connectTimeout);
-        auto dataInput2 = m_connectionManager->getCacheImpl()->createDataInput(
-            reinterpret_cast<const uint8_t*>(recvMsgLenBytes.data()),
-            recvMsgLenBytes.size());
-        recvMsgLen = dataInput2.readInt32();
-      }
+      // Read the DistributedMember object
+      auto recvMsgLen = readHandshakeArraySize(connectTimeout);
       auto recvMessage = readHandshakeData(recvMsgLen, connectTimeout);
       // If the distributed member has not been set yet, set it.
       if (getEndpointObject()->getDistributedMemberID() == 0) {
@@ -1143,39 +1128,26 @@ std::shared_ptr<CacheableBytes> TcrConnection::readHandshakeByteArray(
 }
 
 // read a byte array
-uint32_t TcrConnection::readHandshakeArraySize(
+int32_t TcrConnection::readHandshakeArraySize(
     std::chrono::microseconds connectTimeout) {
-  auto codeBytes = readHandshakeData(1, connectTimeout);
-  auto codeDI = m_connectionManager->getCacheImpl()->createDataInput(
-      reinterpret_cast<const uint8_t*>(codeBytes.data()), codeBytes.size());
-  uint8_t code = codeDI.read();
-  uint32_t arraySize = 0;
-  if (code == 0xFF) {
-    return 0;
-  } else {
-    int32_t tempLen = code;
-    if (tempLen > 252) {  // 252 is java's ((byte)-4 && 0xFF)
-      if (code == 0xFE) {
-        auto lenBytes = readHandshakeData(2, connectTimeout);
-        auto lenDI = m_connectionManager->getCacheImpl()->createDataInput(
-            reinterpret_cast<const uint8_t*>(lenBytes.data()), lenBytes.size());
-        uint16_t val = lenDI.readInt16();
-        tempLen = val;
-      } else if (code == 0xFD) {
-        auto lenBytes = readHandshakeData(4, connectTimeout);
-        auto lenDI = m_connectionManager->getCacheImpl()->createDataInput(
-            reinterpret_cast<const uint8_t*>(lenBytes.data()), lenBytes.size());
-        uint32_t val = lenDI.readInt32();
-        tempLen = val;
-      } else {
-        GF_SAFE_DELETE_CON(m_conn);
-        throwException(IllegalStateException("unexpected array length code"));
-      }
-    }
-    arraySize = tempLen;
+  auto arrayLenHeader = readHandshakeData(1, connectTimeout);
+
+  int32_t arrayLength = static_cast<uint8_t>(arrayLenHeader[0]);
+  if (static_cast<int8_t>(arrayLenHeader[0]) == -2) {
+    auto arrayLengthBytes = readHandshakeData(2, connectTimeout);
+    auto dataInput2 = m_connectionManager->getCacheImpl()->createDataInput(
+        reinterpret_cast<const uint8_t*>(arrayLengthBytes.data()),
+        arrayLengthBytes.size());
+    arrayLength = dataInput2.readInt16();
+  } else if (static_cast<int8_t>(arrayLenHeader[0]) == -3) {
+    auto arrayLengthBytes = readHandshakeData(4, connectTimeout);
+    auto dataInput2 = m_connectionManager->getCacheImpl()->createDataInput(
+        reinterpret_cast<const uint8_t*>(arrayLengthBytes.data()),
+        arrayLengthBytes.size());
+    arrayLength = dataInput2.readInt32();
   }
 
-  return arraySize;
+  return arrayLength;
 }
 
 void TcrConnection::readHandshakeInstantiatorMsg(
diff --git a/cppcache/src/TcrConnection.hpp b/cppcache/src/TcrConnection.hpp
index 64d78e4..cd5bb21 100644
--- a/cppcache/src/TcrConnection.hpp
+++ b/cppcache/src/TcrConnection.hpp
@@ -338,7 +338,7 @@ class APACHE_GEODE_EXPORT TcrConnection {
   /*
    * To read the arraysize
    */
-  uint32_t readHandshakeArraySize(std::chrono::microseconds connectTimeout);
+  int32_t readHandshakeArraySize(std::chrono::microseconds connectTimeout);
 
   /*
    * This function reads "numberOfBytes" and ignores it.