Fixed a bug by correctly invoking CAConvertAddrToName API
authorSachin Agrawal <sachin.agrawal@intel.com>
Sat, 8 Aug 2015 00:23:56 +0000 (17:23 -0700)
committerSachin Agrawal <sachin.agrawal@intel.com>
Sun, 9 Aug 2015 18:52:44 +0000 (18:52 +0000)
Recently, DTLS code in CA layer was updated to use
CAConvertAddrtoName() API instead of inet_ntoa. The API was
wrongly invoked by passing invalid arguments. This caused
failure in security samples.

Change-Id: I33a3981ca1c2ed0635b8def5106282349df611ee
Signed-off-by: Sachin Agrawal <sachin.agrawal@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2149
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Shilpa Sodani <shilpa.a.sodani@intel.com>
resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c

index 8439896..97a72bf 100644 (file)
@@ -80,7 +80,7 @@ static CAEndpoint_t *GetPeerInfo(const CAEndpoint_t *peer)
     return NULL;
 }
 
-static CAResult_t CAAddIdToPeerInfoList(const char *peerAddr, uint32_t port,
+static CAResult_t CAAddIdToPeerInfoList(const char *peerAddr, uint16_t port,
         const unsigned char *id, uint16_t id_length, CATransportFlags_t flag)
 {
     if(NULL == peerAddr
@@ -139,7 +139,7 @@ static void CAFreePeerInfoList()
     g_caDtlsContext->peerInfoList = NULL;
 }
 
-static void CARemovePeerFromPeerInfoList(const char * addr, uint32_t port)
+static void CARemovePeerFromPeerInfoList(const char * addr, uint16_t port)
 {
     if (NULL == addr || 0 >= port)
     {
@@ -483,9 +483,9 @@ static int32_t CAHandleSecureEvent(dtls_context_t *context,
         OIC_LOG(INFO, NET_DTLS_TAG, "Peer closing connection");
 
         stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
-        char *peerAddr = NULL;
-        uint32_t port = 0;
-        CAConvertAddrToName(&(addrInfo->addr.st), peerAddr, port);
+        char peerAddr[MAX_ADDR_STR_SIZE_CA] = {0};
+        uint16_t port = 0;
+        CAConvertAddrToName(&(addrInfo->addr.st), peerAddr, &port);
         CARemovePeerFromPeerInfoList(peerAddr, port);
     }
 
@@ -550,9 +550,9 @@ static int32_t CAGetPskCredentials(dtls_context_t *ctx,
                     // data structure when handshake completes. Therefore, currently this is a
                     // workaround to cache remote end-point identity when tinyDTLS asks for PSK.
                     stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
-                    char *peerAddress = NULL;
-                    uint32_t port = 0;
-                    CAConvertAddrToName(&(addrInfo->addr.st), peerAddress, port);
+                    char peerAddress[MAX_ADDR_STR_SIZE_CA] = {0};
+                    uint16_t port = 0;
+                    CAConvertAddrToName(&(addrInfo->addr.st), peerAddress, &port);
 
                     CATransportFlags_t flag =
                             addrInfo->addr.st.ss_family == AF_INET ? CA_IPV4 : CA_IPV6;