From 4667f8b18e45b67022a0dc0966ad85c572d52f53 Mon Sep 17 00:00:00 2001 From: Jaewook Jung Date: Thu, 17 Nov 2016 13:14:43 +0900 Subject: [PATCH] [IOT-1570] fixed a crash issue related to block-wise transfer When a resource server receives 4.08 error response from a resource client, the server will try to send the response from the first block again. But now, the server assumes the message type that has to be sent for receiving 4.08 error is only request message. So I modified to handle it up to the message type. Change-Id: I555b5dd5c44b73647c2543de551aba6f5113f909 Signed-off-by: Jaewook Jung Reviewed-on: https://gerrit.iotivity.org/gerrit/14433 Tested-by: jenkins-iotivity Reviewed-by: Ashok Babu Channa --- .../csdk/connectivity/src/cablockwisetransfer.c | 39 +++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/resource/csdk/connectivity/src/cablockwisetransfer.c b/resource/csdk/connectivity/src/cablockwisetransfer.c index 6c01979..c49c024 100644 --- a/resource/csdk/connectivity/src/cablockwisetransfer.c +++ b/resource/csdk/connectivity/src/cablockwisetransfer.c @@ -643,21 +643,26 @@ CAResult_t CASendBlockMessage(const coap_pdu_t *pdu, CAMessageType_t msgType, } else { - // if the received response message type is CON, send empty message. - // and then, send next block request message with new messagId. - if (msgType == CA_MSG_CONFIRM) - { - CASendDirectEmptyResponse(data->remoteEndpoint, - data->requestInfo->info.messageId); - sentMsgType = CA_MSG_CONFIRM; - } - if (data->requestInfo) { + // if the received response message type is CON, send empty message. + // and then, send next block request message with new messagId. + if (msgType == CA_MSG_CONFIRM) + { + CASendDirectEmptyResponse(data->remoteEndpoint, + data->requestInfo->info.messageId); + sentMsgType = CA_MSG_CONFIRM; + } + OIC_LOG(DEBUG, TAG, "need new msgID"); data->requestInfo->info.messageId = 0; data->requestInfo->info.type = sentMsgType; } + else if (data->responseInfo) + { + data->responseInfo->info.messageId = pdu->transport_hdr->udp.id; + data->responseInfo->info.type = sentMsgType; + } } // add data to send thread @@ -1864,7 +1869,11 @@ uint8_t CACheckBlockErrorType(CABlockData_t *currData, coap_block_t *receivedBlo OIC_LOG(ERROR, TAG, "it didn't order"); return CA_BLOCK_INCOMPLETE; } - return CA_BLOCK_RECEIVED_ALREADY; + else + { + OIC_LOG(ERROR, TAG, "already received this block"); + return CA_BLOCK_RECEIVED_ALREADY; + } } } @@ -2608,8 +2617,14 @@ void CADestroyDataSet(CAData_t* data) VERIFY_NON_NULL_VOID(data, TAG, "data"); CAFreeEndpoint(data->remoteEndpoint); - CADestroyRequestInfoInternal(data->requestInfo); - CADestroyResponseInfoInternal(data->responseInfo); + if (data->requestInfo) + { + CADestroyRequestInfoInternal(data->requestInfo); + } + if (data->responseInfo) + { + CADestroyResponseInfoInternal(data->responseInfo); + } OICFree(data); } -- 2.7.4