From: Jaewook Jung Date: Fri, 2 Dec 2016 07:07:22 +0000 (+0900) Subject: added fail case for coap_add_option2 X-Git-Tag: 1.3.0~1049^2~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c580ea569a59a776ae121e4523b0f55bca25fbb2;p=platform%2Fupstream%2Fiotivity.git added fail case for coap_add_option2 If coap_add_option2 fails, it has to return fail while sending data. Otherwise, it causes a crash error when it tries to use a pdu wrong. The below is the comment for coap_add_option2 on libcoap-4.1.1 /** * Adds option of given type to pdu that is passed as first * parameter. coap_add_option2() destroys the PDU's data, so * coap_add_data() must be called after all options have been added. * As coap_add_token2() destroys the options following the token, * the token must be added before coap_add_option2() is called. * This function returns the number of bytes written or @c 0 on error. */ size_t coap_add_option2(coap_pdu_t *pdu, unsigned short type, unsigned int len, const unsigned char *data, coap_transport_t transport); Change-Id: I405c77a63902d9c48b50cb9b94448a9f0e1990f0 Signed-off-by: Jaewook Jung Reviewed-on: https://gerrit.iotivity.org/gerrit/15053 Tested-by: jenkins-iotivity Reviewed-by: Dan Mihai Reviewed-by: Phil Coval Reviewed-by: Hyuna Jo Reviewed-by: Ashok Babu Channa --- diff --git a/resource/csdk/connectivity/src/caprotocolmessage.c b/resource/csdk/connectivity/src/caprotocolmessage.c index b614372..9a9cd8c 100644 --- a/resource/csdk/connectivity/src/caprotocolmessage.c +++ b/resource/csdk/connectivity/src/caprotocolmessage.c @@ -378,9 +378,14 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info, COAP_OPTION_DATA(*(coap_option *) opt->data)); OIC_LOG_V(DEBUG, TAG, "[%d] pdu length", pdu->length); - coap_add_option2(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data), - COAP_OPTION_LENGTH(*(coap_option *) opt->data), - COAP_OPTION_DATA(*(coap_option *) opt->data), *transport); + if (0 == coap_add_option2(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data), + COAP_OPTION_LENGTH(*(coap_option *) opt->data), + COAP_OPTION_DATA(*(coap_option *) opt->data), *transport)) + { + OIC_LOG(ERROR, TAG, "coap_add_option2 has failed"); + coap_delete_pdu(pdu); + return NULL; + } } }