From 9c25a43b49586baab931f56246dae1080c8372b0 Mon Sep 17 00:00:00 2001 From: "jihwan.seo" Date: Wed, 14 Oct 2015 14:09:54 +0900 Subject: [PATCH] Added error check code for Reset with no empty message. Reset must be empty message by spec rfc 7252. both receiver and sender applied to check whether reset has empty message or not. Change-Id: I0aaeec22bbeda1ffd893e488f74450eb31b742ae Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/3873 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- resource/csdk/connectivity/src/caprotocolmessage.c | 9 +++++++-- resource/csdk/connectivity/src/caretransmission.c | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/resource/csdk/connectivity/src/caprotocolmessage.c b/resource/csdk/connectivity/src/caprotocolmessage.c index 58ca291..7861f17 100644 --- a/resource/csdk/connectivity/src/caprotocolmessage.c +++ b/resource/csdk/connectivity/src/caprotocolmessage.c @@ -120,8 +120,13 @@ coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_ // and ACKNOWLEDGE can use empty message when code is empty. if (CA_MSG_RESET == info->type || (CA_EMPTY == code && CA_MSG_ACKNOWLEDGE == info->type)) { - if ((CA_EMPTY == code) && (info->payloadSize > 0 || info->payload - || info->token || info->tokenLength > 0)) + if (CA_EMPTY != code) + { + OIC_LOG(ERROR, TAG, "reset is not empty message"); + return NULL; + } + + if (info->payloadSize > 0 || info->payload || info->token || info->tokenLength > 0) { OIC_LOG(ERROR, TAG, "Empty message has unnecessary data after messageID"); return NULL; diff --git a/resource/csdk/connectivity/src/caretransmission.c b/resource/csdk/connectivity/src/caretransmission.c index 125ae10..264b7a7 100644 --- a/resource/csdk/connectivity/src/caretransmission.c +++ b/resource/csdk/connectivity/src/caretransmission.c @@ -490,10 +490,13 @@ CAResult_t CARetransmissionReceivedData(CARetransmission_t *context, // ACK, RST --> remove the CON data CAMessageType_t type = CAGetMessageTypeFromPduBinaryData(pdu, size); uint16_t messageId = CAGetMessageIdFromPduBinaryData(pdu, size); + CAResponseResult_t code = CAGetCodeFromPduBinaryData(pdu, size); - OIC_LOG_V(DEBUG, TAG, "received pdu, msgtype=%d, msgid=%d", type, messageId); + OIC_LOG_V(DEBUG, TAG, "received pdu, msgtype=%d, msgid=%d, code=%d", + type, messageId, code); - if ((CA_MSG_ACKNOWLEDGE != type) && (CA_MSG_RESET != type)) + if (((CA_MSG_ACKNOWLEDGE != type) && (CA_MSG_RESET != type)) + || (CA_MSG_RESET == type && CA_EMPTY != code)) { return CA_STATUS_OK; } -- 2.7.4