From 568aadcf098ba0270ce92941a81488ffa12a6041 Mon Sep 17 00:00:00 2001 From: Pawel Winogrodzki Date: Tue, 21 Feb 2017 18:29:14 -0800 Subject: [PATCH] IOT-1583: Removing /W3 warnings inside connectivity/ (part 1) Removing the /W3 warnings in order to add the /WX option to prevent new ones from being added inside the resource/csdk/connectivity/ directory. Change-Id: Ibd53ad378b5d960ea59f2e2c61254a9257d03a3e Signed-off-by: Pawel Winogrodzki Reviewed-on: https://gerrit.iotivity.org/gerrit/17419 Tested-by: jenkins-iotivity Reviewed-by: Dan Mihai --- bridging/common/pipeHandler.cpp | 2 +- build_common/windows/SConscript | 5 +- resource/csdk/connectivity/api/cacommon.h | 1 + resource/csdk/connectivity/api/cainterface.h | 2 +- .../csdk/connectivity/common/inc/cacommonutil.h | 31 ++- resource/csdk/connectivity/common/inc/uarraylist.h | 12 +- .../common/src/cathreadpool_pthreads.c | 4 +- resource/csdk/connectivity/common/src/uarraylist.c | 16 +- .../csdk/connectivity/inc/ca_adapter_net_ssl.h | 4 +- .../csdk/connectivity/inc/caadapterinterface.h | 2 +- .../csdk/connectivity/inc/cablockwisetransfer.h | 4 +- .../csdk/connectivity/inc/cainterfacecontroller.h | 2 +- .../csdk/connectivity/inc/canetworkconfigurator.h | 2 +- .../src/adapter_util/ca_adapter_net_ssl.c | 266 +++++++++++++-------- .../src/adapter_util/cafragmentation.c | 3 +- .../csdk/connectivity/src/cablockwisetransfer.c | 78 +++--- .../csdk/connectivity/src/caconnectivitymanager.c | 2 +- .../csdk/connectivity/src/cainterfacecontroller.c | 44 ++-- resource/csdk/connectivity/src/camessagehandler.c | 7 +- .../csdk/connectivity/src/canetworkconfigurator.c | 6 +- resource/csdk/connectivity/src/caprotocolmessage.c | 38 ++- resource/csdk/connectivity/src/caretransmission.c | 25 +- .../csdk/connectivity/test/ca_api_unittest.cpp | 4 +- .../csdk/connectivity/test/ssladapter_test.cpp | 62 ++--- resource/csdk/logger/include/logger.h | 1 + .../csdk/stack/include/internal/ocstackinternal.h | 4 +- .../samples/linux/SimpleClientServer/occlient.cpp | 1 + .../samples/linux/secure/occlientdirectpairing.cpp | 1 + resource/csdk/stack/src/ocpayload.c | 8 +- resource/csdk/stack/src/ocresource.c | 6 +- resource/csdk/stack/src/oickeepalive.c | 22 +- resource/csdk/stack/test/stacktests.cpp | 4 +- .../enrollee/unittests/ESMediatorSimulator.h | 6 +- .../mediator/richsdk/unittests/ESMediatorTest.cpp | 6 +- service/scene-manager/src/SceneUtils.cpp | 4 +- 35 files changed, 401 insertions(+), 284 deletions(-) diff --git a/bridging/common/pipeHandler.cpp b/bridging/common/pipeHandler.cpp index eb97286..20a1879 100644 --- a/bridging/common/pipeHandler.cpp +++ b/bridging/common/pipeHandler.cpp @@ -25,6 +25,7 @@ * functions to write to the pipe and read from the pipe. */ +#include #include #include #include "messageHandler.h" @@ -35,7 +36,6 @@ #include "platform_features.h" #include "oic_malloc.h" #include "logger.h" -#include #define TAG "PIPE_HANDLER" diff --git a/build_common/windows/SConscript b/build_common/windows/SConscript index bcd8911..8906bdf 100644 --- a/build_common/windows/SConscript +++ b/build_common/windows/SConscript @@ -6,14 +6,15 @@ import os.path # Set common flags if env['CC'] == 'cl': - # Enable warnings as errors. # - warning C4133: incompatible type conversion env.AppendUnique(CCFLAGS=['/we4133']) # Disable the following warnings: # - warning C4127: conditional expression is constant # - Disabled due to the widespread usage in IoTivity - env.AppendUnique(CCFLAGS=['/wd4127']) + # - warning C4200: zero-sized array in struct/union. + # - It is an acceptable approach for variable size structs. + env.AppendUnique(CCFLAGS=['/wd4127', '/wd4200']) env.AppendUnique(CCFLAGS=['/EHsc']) diff --git a/resource/csdk/connectivity/api/cacommon.h b/resource/csdk/connectivity/api/cacommon.h index ef60fc9..340a8a0 100755 --- a/resource/csdk/connectivity/api/cacommon.h +++ b/resource/csdk/connectivity/api/cacommon.h @@ -28,6 +28,7 @@ #include "iotivity_config.h" +#include #include #include #include diff --git a/resource/csdk/connectivity/api/cainterface.h b/resource/csdk/connectivity/api/cainterface.h index 1531ebf..578ff0a 100644 --- a/resource/csdk/connectivity/api/cainterface.h +++ b/resource/csdk/connectivity/api/cainterface.h @@ -216,7 +216,7 @@ CAResult_t CAUnSelectNetwork(CATransportAdapter_t nonInterestedNetwork); * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED or * ::CA_STATUS_INVALID_PARAM or ::CA_MEMORY_ALLOC_FAILED */ -CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size); +CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, size_t *size); /** * Get supported network adapter. diff --git a/resource/csdk/connectivity/common/inc/cacommonutil.h b/resource/csdk/connectivity/common/inc/cacommonutil.h index 220ca75..59be952 100644 --- a/resource/csdk/connectivity/common/inc/cacommonutil.h +++ b/resource/csdk/connectivity/common/inc/cacommonutil.h @@ -32,17 +32,38 @@ extern "C" /** * Macro to verify the validity of input argument. * + * @param expr Expression to verify. + * @param log_tag Log tag. + * @param log_message Log message. + */ +#define VERIFY_TRUE(expr, log_tag, log_message) \ + VERIFY_TRUE_RET((expr), (log_tag), (log_message), CA_STATUS_INVALID_PARAM) + +/** + * Macro to verify the validity of input argument. + * + * @param expr Expression to verify. + * @param log_tag Log tag. + * @param log_message Log message. + * @param ret Return value. + */ +#define VERIFY_TRUE_RET(expr, log_tag, log_message, ret) \ + if (!(expr)) \ + { \ + OIC_LOG_V(ERROR, (log_tag), "Invalid input: %s", (log_message)); \ + return (ret); \ + } \ + +/** + * Macro to verify the validity of input argument. + * * @param arg log level * @param log_tag log tag * @param log_message log message * @param ret return value */ #define VERIFY_NON_NULL_RET(arg, log_tag, log_message, ret) \ - if (NULL == (arg)) \ - { \ - OIC_LOG_V(ERROR, (log_tag), "Invalid input:%s", (log_message)); \ - return (ret); \ - } \ + VERIFY_TRUE_RET(NULL != (arg), (log_tag), (log_message), (ret)) /** * Macro to verify the validity of input argument. diff --git a/resource/csdk/connectivity/common/inc/uarraylist.h b/resource/csdk/connectivity/common/inc/uarraylist.h index cf1085b..e7864d8 100644 --- a/resource/csdk/connectivity/common/inc/uarraylist.h +++ b/resource/csdk/connectivity/common/inc/uarraylist.h @@ -39,8 +39,8 @@ extern "C" typedef struct u_arraylist_t { void **data; - uint32_t length; - uint32_t capacity; + size_t length; + size_t capacity; } u_arraylist_t; /** @@ -86,7 +86,7 @@ void u_arraylist_shrink_to_fit(u_arraylist_t *list); * @param[in] index index of array list. * @return void pointer of data if success or NULL pointer otherwise. */ -void *u_arraylist_get(const u_arraylist_t *list, uint32_t index); +void *u_arraylist_get(const u_arraylist_t *list, size_t index); /** * Returns the index of the data from the array list. @@ -95,7 +95,7 @@ void *u_arraylist_get(const u_arraylist_t *list, uint32_t index); * @param[out]index index of array list. * @return true if success, false otherwise. */ -bool u_arraylist_get_index(const u_arraylist_t *list, const void *data, uint32_t *index); +bool u_arraylist_get_index(const u_arraylist_t *list, const void *data, size_t *index); /** * Add data in the array list. @@ -111,14 +111,14 @@ bool u_arraylist_add(u_arraylist_t *list, void *data); * @param[in] index index of array list. * @return void pointer of the data if success or NULL pointer otherwise. */ -void *u_arraylist_remove(u_arraylist_t *list, uint32_t index); +void *u_arraylist_remove(u_arraylist_t *list, size_t index); /** * Returns the length of the array list. * @param[in] list pointer of array list. * @return length of the array list. */ -uint32_t u_arraylist_length(const u_arraylist_t *list); +size_t u_arraylist_length(const u_arraylist_t *list); /** * Returns whether the data exists or not. diff --git a/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c b/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c index cd2acd3..2caa716 100644 --- a/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c +++ b/resource/csdk/connectivity/common/src/cathreadpool_pthreads.c @@ -188,7 +188,7 @@ CAResult_t ca_thread_pool_add_task(ca_thread_pool_t thread_pool, ca_thread_func int thrRet = oc_thread_new(&threadInfo->thread, ca_thread_pool_pthreads_delegate, info); if (thrRet != 0) { - uint32_t index = 0; + size_t index = 0; if (u_arraylist_get_index(thread_pool->details->threads_list, threadInfo, &index)) { u_arraylist_remove(thread_pool->details->threads_list, index); @@ -216,7 +216,7 @@ void ca_thread_pool_free(ca_thread_pool_t thread_pool) oc_mutex_lock(thread_pool->details->list_lock); - for (uint32_t i = 0; i < u_arraylist_length(thread_pool->details->threads_list); ++i) + for (size_t i = 0; i < u_arraylist_length(thread_pool->details->threads_list); ++i) { ca_thread_pool_thread_info_t *threadInfo = (ca_thread_pool_thread_info_t *) u_arraylist_get(thread_pool->details->threads_list, i); diff --git a/resource/csdk/connectivity/common/src/uarraylist.c b/resource/csdk/connectivity/common/src/uarraylist.c index 269efdb..b42794b 100644 --- a/resource/csdk/connectivity/common/src/uarraylist.c +++ b/resource/csdk/connectivity/common/src/uarraylist.c @@ -110,7 +110,7 @@ void u_arraylist_shrink_to_fit(u_arraylist_t *list) } } -void *u_arraylist_get(const u_arraylist_t *list, uint32_t index) +void *u_arraylist_get(const u_arraylist_t *list, size_t index) { if (!list ) { @@ -125,14 +125,14 @@ void *u_arraylist_get(const u_arraylist_t *list, uint32_t index) return NULL; } -bool u_arraylist_get_index(const u_arraylist_t *list, const void *data, uint32_t *index) +bool u_arraylist_get_index(const u_arraylist_t *list, const void *data, size_t *index) { if (!list || !data) { return false; } - for (uint32_t i = 0; i < list->length; i++) + for (size_t i = 0; i < list->length; i++) { if (data == list->data[i]) { @@ -169,7 +169,7 @@ bool u_arraylist_add(u_arraylist_t *list, void *data) list->data = (void **) tmp; memset(list->data + list->capacity, 0, (new_capacity - list->capacity) * sizeof(list->data[0])); - list->capacity = (uint32_t)new_capacity; + list->capacity = new_capacity; } list->data[list->length] = data; @@ -178,7 +178,7 @@ bool u_arraylist_add(u_arraylist_t *list, void *data) return true; } -void *u_arraylist_remove(u_arraylist_t *list, uint32_t index) +void *u_arraylist_remove(u_arraylist_t *list, size_t index) { void *removed = NULL; @@ -201,7 +201,7 @@ void *u_arraylist_remove(u_arraylist_t *list, uint32_t index) return removed; } -uint32_t u_arraylist_length(const u_arraylist_t *list) +size_t u_arraylist_length(const u_arraylist_t *list) { if (!list) { @@ -218,7 +218,7 @@ bool u_arraylist_contains(const u_arraylist_t *list, const void *data) return false; } - for (uint32_t i = 0; i < list->length; i++) + for (size_t i = 0; i < list->length; i++) { if (data == list->data[i]) { @@ -236,7 +236,7 @@ void u_arraylist_destroy(u_arraylist_t *list) { return; } - for (uint32_t i = 0; i < list->length; i++) + for (size_t i = 0; i < list->length; i++) { OICFree(list->data[i]); } diff --git a/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h b/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h index e6098d8..12cde83 100644 --- a/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h +++ b/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h @@ -123,7 +123,7 @@ void CAdeinitSslAdapter(); * */ -CAResult_t CAencryptSsl(const CAEndpoint_t *endpoint, void *data, uint32_t dataLen); +CAResult_t CAencryptSsl(const CAEndpoint_t *endpoint, void *data, size_t dataLen); /** * Performs TLS decryption of the data. @@ -138,7 +138,7 @@ CAResult_t CAencryptSsl(const CAEndpoint_t *endpoint, void *data, uint32_t dataL * @retval ::CA_STATUS_FAILED Operation failed. * */ -CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t dataLen); +CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, size_t dataLen); /** * Initiate TLS handshake with selected cipher suite. diff --git a/resource/csdk/connectivity/inc/caadapterinterface.h b/resource/csdk/connectivity/inc/caadapterinterface.h index 90a53cc..7d15791 100644 --- a/resource/csdk/connectivity/inc/caadapterinterface.h +++ b/resource/csdk/connectivity/inc/caadapterinterface.h @@ -114,7 +114,7 @@ typedef int32_t (*CAAdapterSendMulticastData)(const CAEndpoint_t *endpoint, * @param[out] size Number of local connectivity structures. * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h) */ -typedef CAResult_t (*CAAdapterGetNetworkInfo)(CAEndpoint_t **info, uint32_t *size); +typedef CAResult_t (*CAAdapterGetNetworkInfo)(CAEndpoint_t **info, size_t *size); /** * Read Synchronous API callback. diff --git a/resource/csdk/connectivity/inc/cablockwisetransfer.h b/resource/csdk/connectivity/inc/cablockwisetransfer.h index 3581186..80218e0 100644 --- a/resource/csdk/connectivity/inc/cablockwisetransfer.h +++ b/resource/csdk/connectivity/inc/cablockwisetransfer.h @@ -477,14 +477,14 @@ CAPayload_t CAGetPayloadInfo(const CAData_t *data, size_t *payloadLen); * @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ CAResult_t CAUpdateBlockOptionType(const CABlockDataID_t *blockID, - uint8_t blockType); + uint16_t blockType); /** * Get the block option type from block-wise transfer list. * @param[in] blockID ID set of CABlockData. * @return block option type. */ -uint8_t CAGetBlockOptionType(const CABlockDataID_t *blockID); +uint16_t CAGetBlockOptionType(const CABlockDataID_t *blockID); /** * Get the block data from block-wise transfer list. diff --git a/resource/csdk/connectivity/inc/cainterfacecontroller.h b/resource/csdk/connectivity/inc/cainterfacecontroller.h index c4e44b9..56c3e5a 100644 --- a/resource/csdk/connectivity/inc/cainterfacecontroller.h +++ b/resource/csdk/connectivity/inc/cainterfacecontroller.h @@ -118,7 +118,7 @@ CAResult_t CASetAdapterRAInfo(const CARAInfo_t *caraInfo); * @param[out] size number of connectivity information structures. * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ -CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size); +CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, size_t *size); /** * Sends unicast data to the remote endpoint. diff --git a/resource/csdk/connectivity/inc/canetworkconfigurator.h b/resource/csdk/connectivity/inc/canetworkconfigurator.h index 775c516..4dcce70 100644 --- a/resource/csdk/connectivity/inc/canetworkconfigurator.h +++ b/resource/csdk/connectivity/inc/canetworkconfigurator.h @@ -61,7 +61,7 @@ u_arraylist_t *CAGetSelectedNetworkList(); * @param[out] size No Of Array objects. * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ -CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, uint32_t *size); +CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, size_t *size); /** * Terminate network type from selected configuration. diff --git a/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c b/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c index ac375fb..0cd3bdd 100755 --- a/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c +++ b/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c @@ -202,59 +202,7 @@ if (g_sslCallback) errorInfo.result = (status); \ g_sslCallback(&(peer)->sep.endpoint, &errorInfo); \ } -/**@def SSL_CHECK_FAIL(peer, ret, str, mutex, error, msg) - * - * Checks handshake result and send alert if needed. - * - * @param[in] peer remote peer - * @param[in] ret error code - * @param[in] str debug string - * @param[in] mutex ca mutex - * @param[in] if code does not equal to -1 returns error code - * @param[in] msg allert message - */ -#define SSL_CHECK_FAIL(peer, ret, str, mutex, error, msg) \ -if (0 != (ret) && MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY != (int) (ret) && \ - MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED != (int) (ret) && \ - MBEDTLS_ERR_SSL_WANT_READ != (int) (ret) && \ - MBEDTLS_ERR_SSL_WANT_WRITE != (int) (ret) && \ - MBEDTLS_ERR_SSL_NON_FATAL != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_USER_CANCELED != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_NO_CERT != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_BAD_CERT != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY != (int) (ret) && \ - MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL != (int) (ret)) \ -{ \ - OIC_LOG_V(ERROR, NET_SSL_TAG, "%s: -0x%x", (str), -(ret)); \ - if ((int) MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE != (int) (ret) && \ - (int) MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO != (int) (ret)) \ - { \ - mbedtls_ssl_send_alert_message(&(peer)->ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, (msg)); \ - } \ - RemovePeerFromList(&(peer)->sep.endpoint); \ - if (mutex) \ - { \ - oc_mutex_unlock(g_sslContextMutex); \ - } \ - if ((int) MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO != (int)(ret)) \ - { \ - SSL_RES((peer), CA_DTLS_AUTHENTICATION_FAILURE); \ - } \ - OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); \ - if (-1 != error) \ - { \ - return (error); \ - } \ -} + /**@def CONF_SSL(clientConf, serverConf, fn, ...) * * Calls \a fn for \a clientConf and \a serverConf. @@ -557,18 +505,19 @@ static int SendCallBack(void * tep, const unsigned char * data, size_t dataLen) VERIFY_NON_NULL_RET(tep, NET_SSL_TAG, "secure endpoint is NULL", -1); VERIFY_NON_NULL_RET(data, NET_SSL_TAG, "data is NULL", -1); VERIFY_NON_NULL_RET(g_caSslContext, NET_SSL_TAG, "SSL Context is NULL", -1); - OIC_LOG_V(DEBUG, NET_SSL_TAG, "Data len: %zu", dataLen); + OIC_LOG_V(DEBUG, NET_SSL_TAG, "Data len: %" PRIuPTR, dataLen); OIC_LOG_V(DEBUG, NET_SSL_TAG, "Adapter: %u", ((SslEndPoint_t * )tep)->sep.endpoint.adapter); ssize_t sentLen = 0; int adapterIndex = GetAdapterIndex(((SslEndPoint_t * )tep)->sep.endpoint.adapter); if (0 <= adapterIndex && MAX_SUPPORTED_ADAPTERS > adapterIndex) { + size_t dataToSend = (dataLen > INT_MAX) ? INT_MAX : dataLen; CAPacketSendCallback sendCallback = g_caSslContext->adapterCallbacks[adapterIndex].sendCallback; - sentLen = sendCallback(&(((SslEndPoint_t * )tep)->sep.endpoint), (const void *) data, dataLen); + sentLen = sendCallback(&(((SslEndPoint_t * )tep)->sep.endpoint), (const void *) data, dataToSend); if (sentLen != dataLen) { OIC_LOG_V(DEBUG, NET_SSL_TAG, - "Packet was partially sent - total/sent/remained bytes : %d/%d/%d", + "Packet was partially sent - sent/total/remained bytes : %d/%" PRIuPTR "/%" PRIuPTR, sentLen, dataLen, (dataLen - sentLen)); } } @@ -579,7 +528,7 @@ static int SendCallBack(void * tep, const unsigned char * data, size_t dataLen) } OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); - return sentLen; + return (int)sentLen; } /** * Read callback. @@ -597,8 +546,8 @@ static int RecvCallBack(void * tep, unsigned char * data, size_t dataLen) VERIFY_NON_NULL_RET(data, NET_SSL_TAG, "data is NULL", 0); SslRecBuf_t *recBuf = &((SslEndPoint_t *)tep)->recBuf; - size_t retLen = (recBuf->len > recBuf->loaded ? recBuf->len - recBuf->loaded : 0); - retLen = (retLen < dataLen ? retLen : dataLen); + size_t retLen = ((recBuf->len > recBuf->loaded) ? (recBuf->len - recBuf->loaded) : 0); + retLen = (retLen < dataLen) ? retLen : dataLen; if (retLen > INT_MAX) { @@ -623,7 +572,7 @@ static int RecvCallBack(void * tep, unsigned char * data, size_t dataLen) * * @return number of successfully parsed certificates or -1 on error */ -static int ParseChain(mbedtls_x509_crt * crt, unsigned char * buf, int bufLen, int * errNum) +static size_t ParseChain(mbedtls_x509_crt * crt, unsigned char * buf, size_t bufLen, int * errNum) { OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__); VERIFY_NON_NULL_RET(crt, NET_SSL_TAG, "Param crt is NULL" , -1); @@ -642,9 +591,9 @@ static int ParseChain(mbedtls_x509_crt * crt, unsigned char * buf, int bufLen, i size_t len = 0; unsigned char * tmp = NULL; - int count = 0; + size_t count = 0; int ret = 0; - int pos = 0; + size_t pos = 0; *errNum = 0; while (pos < bufLen) @@ -760,7 +709,7 @@ static int InitPKIX(CATransportAdapter_t adapter) // optional int ret; int errNum; - int count = ParseChain(&g_caSslContext->crt, g_pkiInfo.crt.data, g_pkiInfo.crt.len, &errNum); + size_t count = ParseChain(&g_caSslContext->crt, g_pkiInfo.crt.data, g_pkiInfo.crt.len, &errNum); if (0 >= count) { OIC_LOG(WARNING, NET_SSL_TAG, "Own certificate chain parsing error"); @@ -838,11 +787,9 @@ static int GetPskCredentialsCallback(void * notUsed, mbedtls_ssl_context * ssl, VERIFY_NON_NULL_RET(g_getCredentialsCallback, NET_SSL_TAG, "Credential callback s NULL", -1); VERIFY_NON_NULL_RET(ssl, NET_SSL_TAG, "ssl pointer is NULL", -1); VERIFY_NON_NULL_RET(desc, NET_SSL_TAG, "desc pointer is NULL", -1); - if (descLen > CA_MAX_ENDPOINT_IDENTITY_LEN) - { - OIC_LOG(ERROR, NET_SSL_TAG, "desc too long!"); - return -1; - } + VERIFY_TRUE_RET((descLen <= CA_MAX_ENDPOINT_IDENTITY_LEN), NET_SSL_TAG, + "desc too long!", -1); + (void) notUsed; uint8_t keyBuf[PSK_LENGTH] = {0}; @@ -851,7 +798,7 @@ static int GetPskCredentialsCallback(void * notUsed, mbedtls_ssl_context * ssl, if (ret > 0) { memcpy(((SslEndPoint_t *) ssl)->sep.identity.id, desc, descLen); - ((SslEndPoint_t *) ssl)->sep.identity.id_length = descLen; + ((SslEndPoint_t *) ssl)->sep.identity.id_length = (uint16_t)descLen; OIC_LOG(DEBUG, NET_SSL_TAG, "PSK:"); OIC_LOG_BUFFER(DEBUG, NET_SSL_TAG, keyBuf, ret); @@ -870,8 +817,8 @@ static int GetPskCredentialsCallback(void * notUsed, mbedtls_ssl_context * ssl, */ static SslEndPoint_t *GetSslPeer(const CAEndpoint_t *peer) { - uint32_t listIndex = 0; - uint32_t listLength = 0; + size_t listIndex = 0; + size_t listLength = 0; OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__); VERIFY_NON_NULL_RET(peer, NET_SSL_TAG, "TLS peer is NULL", NULL); VERIFY_NON_NULL_RET(g_caSslContext, NET_SSL_TAG, "SSL Context is NULL", NULL); @@ -1049,8 +996,8 @@ static void DeleteCacheList(u_arraylist_t * cacheList) { OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__); VERIFY_NON_NULL_VOID(cacheList, NET_SSL_TAG, "cacheList"); - uint32_t listIndex = 0; - uint32_t listLength = 0; + size_t listIndex = 0; + size_t listLength = 0; listLength = u_arraylist_length(cacheList); for (listIndex = 0; listIndex < listLength; listIndex++) @@ -1089,10 +1036,10 @@ static void RemovePeerFromList(CAEndpoint_t * endpoint) { VERIFY_NON_NULL_VOID(g_caSslContext, NET_SSL_TAG, "SSL Context is NULL"); VERIFY_NON_NULL_VOID(endpoint, NET_SSL_TAG, "endpoint"); - uint32_t listLength = u_arraylist_length(g_caSslContext->peerList); - for (uint32_t listIndex = 0; listIndex < listLength; listIndex++) + size_t listLength = u_arraylist_length(g_caSslContext->peerList); + for (size_t listIndex = 0; listIndex < listLength; listIndex++) { - SslEndPoint_t * tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList,listIndex); + SslEndPoint_t * tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList, listIndex); if (NULL == tep) { continue; @@ -1106,6 +1053,64 @@ static void RemovePeerFromList(CAEndpoint_t * endpoint) } } } + + /** + * Checks handshake result. Removes peer from list and sends alert + * if handshake failed. + * + * @param[in] peer Remote peer's endpoint. + * @param[in] ret Error code. + * @param[in] str Debug string. + * @param[in] msg Alert message. + * + * @return - "true" if the SSL handshake was successful. + * - "false" otherwise. + */ +static bool checkSslOperation(SslEndPoint_t* peer, + int ret, + const char* str, + unsigned char msg) +{ + if ((0 != ret) && + (MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY != ret) && + (MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED != ret) && + (MBEDTLS_ERR_SSL_WANT_READ != ret) && + (MBEDTLS_ERR_SSL_WANT_WRITE != ret) && + (MBEDTLS_ERR_SSL_NON_FATAL != ret) && + (MBEDTLS_SSL_ALERT_MSG_USER_CANCELED != ret) && + (MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION != ret) && + (MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT != ret) && + (MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY != ret) && + (MBEDTLS_SSL_ALERT_MSG_NO_CERT != ret) && + (MBEDTLS_SSL_ALERT_MSG_BAD_CERT != ret) && + (MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT != ret) && + (MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED != ret) && + (MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED != ret) && + (MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN != ret) && + (MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK != ret) && + (MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME != ret) && + (MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY != ret) && + (MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL != ret)) + { + OIC_LOG_V(ERROR, NET_SSL_TAG, "%s: -0x%x", (str), -ret); + if ((MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE != ret) && + (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO != ret)) + { + mbedtls_ssl_send_alert_message(&(peer)->ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, (msg)); + } + + if (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO != ret) + { + SSL_RES((peer), CA_DTLS_AUTHENTICATION_FAILURE); + } + + RemovePeerFromList(&(peer)->sep.endpoint); + return false; + } + + return true; +} + /** * Deletes session list. */ @@ -1113,10 +1118,10 @@ static void DeletePeerList() { VERIFY_NON_NULL_VOID(g_caSslContext, NET_SSL_TAG, "SSL Context is NULL"); - uint32_t listLength = u_arraylist_length(g_caSslContext->peerList); - for (uint32_t listIndex = 0; listIndex < listLength; listIndex++) + size_t listLength = u_arraylist_length(g_caSslContext->peerList); + for (size_t listIndex = 0; listIndex < listLength; listIndex++) { - SslEndPoint_t * tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList,listIndex); + SslEndPoint_t * tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList, listIndex); if (NULL == tep) { continue; @@ -1180,10 +1185,10 @@ void CAcloseSslConnectionAll(CATransportAdapter_t transportType) return; } - uint32_t listLength = u_arraylist_length(g_caSslContext->peerList); + size_t listLength = u_arraylist_length(g_caSslContext->peerList); OIC_LOG_V(DEBUG, NET_SSL_TAG, - "Required transport [%d], peer count [%u]", transportType, listLength); - for (uint32_t i = listLength; i > 0; i--) + "Required transport [%d], peer count [%" PRIuPTR "]", transportType, listLength); + for (size_t i = listLength; i > 0; i--) { SslEndPoint_t *tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList, i - 1); if (NULL == tep) @@ -1441,7 +1446,15 @@ static SslEndPoint_t * InitiateTlsHandshake(const CAEndpoint_t *endpoint) RemovePeerFromList(&tep->sep.endpoint); return NULL; } - SSL_CHECK_FAIL(tep, ret, "Handshake error", 0, NULL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); + if (!checkSslOperation(tep, + ret, + "Handshake error", + MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE)) + { + OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); + DeleteSslEndPoint(tep); + return NULL; + } } OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); return tep; @@ -1549,8 +1562,8 @@ static int InitConfig(mbedtls_ssl_config * conf, int transport, int mode) */ static int StartRetransmit() { - uint32_t listIndex = 0; - uint32_t listLength = 0; + size_t listIndex = 0; + size_t listLength = 0; SslEndPoint_t *tep = NULL; oc_mutex_lock(g_sslContextMutex); @@ -1583,8 +1596,14 @@ static int StartRetransmit() //start new timer registerTimer(RETRANSMISSION_TIME, &g_caSslContext->timerId, (void *) StartRetransmit); //unlock & return - SSL_CHECK_FAIL(tep, ret, "Retransmission", 1, CA_STATUS_FAILED, - MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); + if (!checkSslOperation(tep, + ret, + "Retransmission", + MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE)) + { + oc_mutex_unlock(g_sslContextMutex); + return CA_STATUS_FAILED; + } } } } @@ -1776,7 +1795,7 @@ SslCacheMessage_t * NewCacheMessage(uint8_t * data, size_t dataLen) /* Send data via TLS connection. */ CAResult_t CAencryptSsl(const CAEndpoint_t *endpoint, - void *data, uint32_t dataLen) + void *data, size_t dataLen) { int ret = 0; @@ -1788,11 +1807,11 @@ CAResult_t CAencryptSsl(const CAEndpoint_t *endpoint, if (0 == dataLen) { - OIC_LOG_V(ERROR, NET_SSL_TAG, "dataLen is zero [%d]", dataLen); + OIC_LOG_V(ERROR, NET_SSL_TAG, "dataLen is zero [%" PRIuPTR "]", dataLen); return CA_STATUS_FAILED; } - OIC_LOG_V(DEBUG, NET_SSL_TAG, "Data to be encrypted dataLen [%d]", dataLen); + OIC_LOG_V(DEBUG, NET_SSL_TAG, "Data to be encrypted dataLen [%" PRIuPTR "]", dataLen); oc_mutex_lock(g_sslContextMutex); if(NULL == g_caSslContext) @@ -1866,8 +1885,8 @@ static void SendCacheMessages(SslEndPoint_t * tep) OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__); VERIFY_NON_NULL_VOID(tep, NET_SSL_TAG, "Param tep is NULL"); - uint32_t listIndex = 0; - uint32_t listLength = 0; + size_t listIndex = 0; + size_t listLength = 0; listLength = u_arraylist_length(tep->cacheList); for (listIndex = 0; listIndex < listLength;) { @@ -1926,7 +1945,7 @@ void CAsetSslHandshakeCallback(CAErrorCallback tlsHandshakeCallback) /* Read data from TLS connection */ -CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t dataLen) +CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, size_t dataLen) { int ret = 0; OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__); @@ -1962,7 +1981,7 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d if (!ret) { OIC_LOG(ERROR, NET_SSL_TAG, "u_arraylist_add failed!"); - OICFree(peer); + DeleteSslEndPoint(peer); oc_mutex_unlock(g_sslContextMutex); return CA_STATUS_FAILED; } @@ -1993,10 +2012,25 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d if (0 != flags) { OIC_LOG_BUFFER(ERROR, NET_SSL_TAG, (const uint8_t *) &flags, sizeof(flags)); - SSL_CHECK_FAIL(peer, flags, "Cert verification failed", 1, - CA_STATUS_FAILED, GetAlertCode(flags)); + if (!checkSslOperation(peer, + (int)flags, + "Cert verification failed", + GetAlertCode(flags))) + { + oc_mutex_unlock(g_sslContextMutex); + OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); + return CA_STATUS_FAILED; + } + } + if (!checkSslOperation(peer, + ret, + "Handshake error", + MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE)) + { + oc_mutex_unlock(g_sslContextMutex); + OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); + return CA_STATUS_FAILED; } - SSL_CHECK_FAIL(peer, ret, "Handshake error", 1, CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); if (MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC == peer->ssl.state) { memcpy(peer->master, peer->ssl.session_negotiate->master, sizeof(peer->master)); @@ -2025,8 +2059,15 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d void * userIdPos = NULL; const mbedtls_x509_crt * peerCert = mbedtls_ssl_get_peer_cert(&peer->ssl); ret = (NULL == peerCert ? -1 : 0); - SSL_CHECK_FAIL(peer, ret, "Failed to retrieve cert", 1, - CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_NO_CERT); + if (!checkSslOperation(peer, + ret, + "Failed to retrieve cert", + MBEDTLS_SSL_ALERT_MSG_NO_CERT)) + { + oc_mutex_unlock(g_sslContextMutex); + OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); + return CA_STATUS_FAILED; + } uuidPos = memmem(peerCert->subject_raw.p, peerCert->subject_raw.len, UUID_PREFIX, sizeof(UUID_PREFIX) - 1); @@ -2035,8 +2076,15 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d memcpy(uuid, (char*) uuidPos + sizeof(UUID_PREFIX) - 1, UUID_LENGTH * 2 + 4); OIC_LOG_V(DEBUG, NET_SSL_TAG, "certificate uuid string: %s" , uuid); ret = (OCConvertStringToUuid(uuid, peer->sep.identity.id)) ? 0 : -1; - SSL_CHECK_FAIL(peer, ret, "Failed to convert subject", 1, - CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT); + if (!checkSslOperation(peer, + ret, + "Failed to convert subject", + MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT)) + { + oc_mutex_unlock(g_sslContextMutex); + OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); + return CA_STATUS_FAILED; + } } else { @@ -2049,8 +2097,15 @@ CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t d { memcpy(uuid, (char*) userIdPos + sizeof(USERID_PREFIX) - 1, UUID_LENGTH * 2 + 4); ret = (OCConvertStringToUuid(uuid, peer->sep.userId.id)) ? 0 : -1; - SSL_CHECK_FAIL(peer, ret, "Failed to convert subject alt name", 1, - CA_STATUS_FAILED, MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT); + if (!checkSslOperation(peer, + ret, + "Failed to convert subject alt name", + MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT)) + { + oc_mutex_unlock(g_sslContextMutex); + OIC_LOG_V(DEBUG, NET_SSL_TAG, "Out %s", __func__); + return CA_STATUS_FAILED; + } } else { @@ -2272,7 +2327,7 @@ CAResult_t CAinitiateSslHandshake(const CAEndpoint_t *endpoint) * @param random2 Random seed. * @param random2Len Actual length of @p random2 (may be zero). * @param buf Output buffer for generated random data. - * @param bufLen Maximum size of @p buf. + * @param bufLen Maximum size of @p buf. Must not be larger than INT_MAX. * * @return The actual number of bytes written to @p buf or @c -1 on error. */ @@ -2288,6 +2343,7 @@ static int pHash (const unsigned char *key, size_t keyLen, size_t dLen; /* digest length */ size_t len = 0; /* result length */ + VERIFY_TRUE_RET(bufLen <= INT_MAX, NET_SSL_TAG, "buffer too large", -1); VERIFY_NON_NULL_RET(key, NET_SSL_TAG, "key is NULL", -1); VERIFY_NON_NULL_RET(label, NET_SSL_TAG, "label is NULL", -1); VERIFY_NON_NULL_RET(random1, NET_SSL_TAG, "random1 is NULL", -1); @@ -2348,7 +2404,7 @@ static int pHash (const unsigned char *key, size_t keyLen, mbedtls_md_free(&hmacA); mbedtls_md_free(&hmacP); - return bufLen; + return (int)bufLen; // exit label required for CHECK_MBEDTLS_RET macro exit: mbedtls_md_free(&hmacA); diff --git a/resource/csdk/connectivity/src/adapter_util/cafragmentation.c b/resource/csdk/connectivity/src/adapter_util/cafragmentation.c index 67bd00b..ff63589 100644 --- a/resource/csdk/connectivity/src/adapter_util/cafragmentation.c +++ b/resource/csdk/connectivity/src/adapter_util/cafragmentation.c @@ -86,7 +86,8 @@ CAResult_t CAGenerateVariableForFragmentation(size_t dataLength, size_t *totalLength, uint16_t mtuSize) { - OIC_LOG_V(DEBUG, TAG, "IN, dataLength = %zu, mtu = %zu", dataLength, mtuSize); + OIC_LOG_V(DEBUG, TAG, "IN, dataLength = %" PRIuPTR ", mtu = %u", + dataLength, (uint32_t)mtuSize); size_t remainDataSize = 0; size_t dataOnlyLen = diff --git a/resource/csdk/connectivity/src/cablockwisetransfer.c b/resource/csdk/connectivity/src/cablockwisetransfer.c index bf31eaf..015fddb 100644 --- a/resource/csdk/connectivity/src/cablockwisetransfer.c +++ b/resource/csdk/connectivity/src/cablockwisetransfer.c @@ -30,6 +30,7 @@ #define _DEFAULT_SOURCE #define _BSD_SOURCE +#include #include #include #include @@ -66,7 +67,7 @@ static bool CACheckPayloadLength(const CAData_t *sendData) // check if message has to be transfered to a block size_t maxBlockSize = BLOCK_SIZE(CA_DEFAULT_BLOCK_SIZE); - OIC_LOG_V(DEBUG, TAG, "payloadLen=%zu, maxBlockSize=%zu", payloadLen, maxBlockSize); + OIC_LOG_V(DEBUG, TAG, "payloadLen=%" PRIuPTR ", maxBlockSize=%" PRIuPTR, payloadLen, maxBlockSize); if (payloadLen <= maxBlockSize) { @@ -311,6 +312,8 @@ CAResult_t CAReceiveBlockWiseData(coap_pdu_t *pdu, const CAEndpoint_t *endpoint, VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr"); VERIFY_NON_NULL(endpoint, TAG, "endpoint"); VERIFY_NON_NULL(receivedData, TAG, "receivedData"); + VERIFY_TRUE((pdu->transport_hdr->udp.token_length <= UINT8_MAX), TAG, + "pdu->transport_hdr->udp.token_length"); // check if received message type is CA_MSG_RESET if (CA_EMPTY == pdu->transport_hdr->udp.code) @@ -397,7 +400,7 @@ CAResult_t CAReceiveBlockWiseData(coap_pdu_t *pdu, const CAEndpoint_t *endpoint, { CABlockDataID_t* blockDataID = CACreateBlockDatablockId( (CAToken_t)pdu->transport_hdr->udp.token, - pdu->transport_hdr->udp.token_length, + (uint8_t)pdu->transport_hdr->udp.token_length, endpoint->addr, endpoint->port); if (NULL == blockDataID || blockDataID->idLength < 1) { @@ -455,7 +458,7 @@ CAResult_t CAReceiveBlockWiseData(coap_pdu_t *pdu, const CAEndpoint_t *endpoint, if (receivedData->responseInfo) { CARemoveBlockDataFromListWithSeed((CAToken_t)pdu->transport_hdr->udp.token, - pdu->transport_hdr->udp.token_length, + (uint8_t)pdu->transport_hdr->udp.token_length, endpoint->addr, endpoint->port); } return CA_NOT_SUPPORTED; @@ -682,6 +685,8 @@ CAResult_t CASendErrorMessage(const coap_pdu_t *pdu, uint8_t status, VERIFY_NON_NULL(pdu, TAG, "pdu"); VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr"); VERIFY_NON_NULL(blockID, TAG, "blockID"); + VERIFY_TRUE((pdu->transport_hdr->udp.token_length <= UINT8_MAX), TAG, + "pdu->transport_hdr->udp.token_length"); // create error responseInfo CABlockData_t *data = CAGetBlockDataFromBlockDataList(blockID); @@ -722,7 +727,7 @@ CAResult_t CASendErrorMessage(const coap_pdu_t *pdu, uint8_t status, } else { - CAInfo_t responseData = { .tokenLength = pdu->transport_hdr->udp.token_length }; + CAInfo_t responseData = { .tokenLength = (uint8_t)pdu->transport_hdr->udp.token_length }; responseData.token = (CAToken_t) OICMalloc(responseData.tokenLength); if (!responseData.token) { @@ -825,7 +830,7 @@ CAResult_t CAReceiveLastBlock(const CABlockDataID_t *blockID, const CAData_t *re static CABlockData_t* CACheckTheExistOfBlockData(const CABlockDataID_t* blockDataID, coap_pdu_t *pdu, const CAEndpoint_t *endpoint, - uint8_t blockType) + uint16_t blockType) { // Get BlockData data. If does not exist, create a new data CABlockData_t *data = CAGetBlockDataFromBlockDataList(blockDataID); @@ -871,12 +876,14 @@ CAResult_t CASetNextBlockOption1(coap_pdu_t *pdu, const CAEndpoint_t *endpoint, VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr"); VERIFY_NON_NULL(endpoint, TAG, "endpoint"); VERIFY_NON_NULL(receivedData, TAG, "receivedData"); + VERIFY_TRUE((pdu->transport_hdr->udp.token_length <= UINT8_MAX), TAG, + "pdu->transport_hdr->udp.token_length"); OIC_LOG_V(INFO, TAG, "num:%d, M:%d, sze:%d", block.num, block.m, block.szx); CABlockDataID_t* blockDataID = CACreateBlockDatablockId( (CAToken_t)pdu->transport_hdr->udp.token, - pdu->transport_hdr->udp.token_length, + (uint8_t)pdu->transport_hdr->udp.token_length, endpoint->addr, endpoint->port); if (NULL == blockDataID || blockDataID->idLength < 1) { @@ -1016,10 +1023,12 @@ CAResult_t CASetNextBlockOption2(coap_pdu_t *pdu, const CAEndpoint_t *endpoint, VERIFY_NON_NULL(pdu->transport_hdr, TAG, "pdu->transport_hdr"); VERIFY_NON_NULL(endpoint, TAG, "endpoint"); VERIFY_NON_NULL(receivedData, TAG, "receivedData"); + VERIFY_TRUE((pdu->transport_hdr->udp.token_length <= UINT8_MAX), TAG, + "pdu->transport_hdr->udp.token_length"); CABlockDataID_t* blockDataID = CACreateBlockDatablockId( (CAToken_t)pdu->transport_hdr->udp.token, - pdu->transport_hdr->udp.token_length, + (uint8_t)pdu->transport_hdr->udp.token_length, endpoint->addr, endpoint->port); if (NULL == blockDataID || blockDataID->idLength < 1) { @@ -1395,18 +1404,22 @@ CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info, VERIFY_NON_NULL(info, TAG, "info"); VERIFY_NON_NULL(endpoint, TAG, "endpoint"); VERIFY_NON_NULL(options, TAG, "options"); + VERIFY_TRUE(((*pdu)->transport_hdr->udp.token_length <= UINT8_MAX), TAG, + "pdu->transport_hdr->udp.token_length"); + VERIFY_TRUE((info->payloadSize <= COAP_MAX_PDU_SIZE), TAG, + "info->payloadSize"); CAResult_t res = CA_STATUS_OK; - size_t dataLength = 0; + unsigned int dataLength = 0; if (info->payload) { - dataLength = info->payloadSize; - OIC_LOG_V(DEBUG, TAG, "dataLength - %zu", dataLength); + dataLength = (unsigned int)info->payloadSize; + OIC_LOG_V(DEBUG, TAG, "dataLength - %" PRIuPTR, dataLength); } CABlockDataID_t* blockDataID = CACreateBlockDatablockId( (CAToken_t)(*pdu)->transport_hdr->udp.token, - (*pdu)->transport_hdr->udp.token_length, + (uint8_t)(*pdu)->transport_hdr->udp.token_length, endpoint->addr, endpoint->port); if (NULL == blockDataID || blockDataID->idLength < 1) { @@ -1423,7 +1436,7 @@ CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info, goto exit; } - uint8_t blockType = CAGetBlockOptionType(blockDataID); + uint16_t blockType = CAGetBlockOptionType(blockDataID); if (COAP_OPTION_BLOCK2 == blockType) { res = CAAddBlockOption2(pdu, info, dataLength, blockDataID, options); @@ -1468,7 +1481,7 @@ CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info, OIC_LOG_V(DEBUG, TAG, "[%d] pdu length after option", (*pdu)->length); // if response data is so large. it have to send as block transfer - if (!coap_add_data(*pdu, dataLength, (const unsigned char *) info->payload)) + if (!coap_add_data(*pdu, dataLength, (const unsigned char*)info->payload)) { OIC_LOG(INFO, TAG, "it has to use block"); res = CA_STATUS_FAILED; @@ -1513,6 +1526,7 @@ CAResult_t CAAddBlockOption2(coap_pdu_t **pdu, const CAInfo_t *info, size_t data VERIFY_NON_NULL(info, TAG, "info"); VERIFY_NON_NULL(blockID, TAG, "blockID"); VERIFY_NON_NULL(options, TAG, "options"); + VERIFY_TRUE((dataLength <= COAP_MAX_PDU_SIZE), TAG, "dataLength"); // get set block data from CABlock list-set. coap_block_t *block1 = CAGetBlockOption(blockID, COAP_OPTION_BLOCK1); @@ -1567,7 +1581,8 @@ CAResult_t CAAddBlockOption2(coap_pdu_t **pdu, const CAInfo_t *info, size_t data goto exit; } - if (!coap_add_block(*pdu, dataLength, (const unsigned char *) info->payload, + if (!coap_add_block(*pdu, (unsigned int)dataLength, + (const unsigned char *) info->payload, block2->num, block2->szx)) { OIC_LOG(ERROR, TAG, "Data length is smaller than the start index"); @@ -1618,6 +1633,7 @@ CAResult_t CAAddBlockOption1(coap_pdu_t **pdu, const CAInfo_t *info, size_t data VERIFY_NON_NULL(info, TAG, "info"); VERIFY_NON_NULL(blockID, TAG, "blockID"); VERIFY_NON_NULL(options, TAG, "options"); + VERIFY_TRUE((dataLength <= COAP_MAX_PDU_SIZE), TAG, "dataLength"); // get set block data from CABlock list-set. coap_block_t *block1 = CAGetBlockOption(blockID, COAP_OPTION_BLOCK1); @@ -1662,7 +1678,8 @@ CAResult_t CAAddBlockOption1(coap_pdu_t **pdu, const CAInfo_t *info, size_t data } // add the payload data as the block size. - if (!coap_add_block(*pdu, dataLength, (const unsigned char *) info->payload, block1->num, + if (!coap_add_block(*pdu, (unsigned int)dataLength, + (const unsigned char *) info->payload, block1->num, block1->szx)) { OIC_LOG(ERROR, TAG, "Data length is smaller than the start index"); @@ -1690,7 +1707,8 @@ CAResult_t CAAddBlockOption1(coap_pdu_t **pdu, const CAInfo_t *info, size_t data } // add the payload data as the block size. - if (!coap_add_data(*pdu, dataLength, (const unsigned char *) info->payload)) + if (!coap_add_data(*pdu, (unsigned int)dataLength, + (const unsigned char*)info->payload)) { OIC_LOG(ERROR, TAG, "failed to add payload"); return CA_STATUS_FAILED; @@ -1764,9 +1782,9 @@ CAResult_t CAAddOptionToPDU(coap_pdu_t *pdu, coap_list_t **options) COAP_OPTION_DATA(*(coap_option *) opt->data)); OIC_LOG_V(DEBUG, TAG, "[%d] pdu length", pdu->length); - int ret = coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data), - COAP_OPTION_LENGTH(*(coap_option *) opt->data), - COAP_OPTION_DATA(*(coap_option *) opt->data)); + size_t ret = coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data), + COAP_OPTION_LENGTH(*(coap_option *) opt->data), + COAP_OPTION_DATA(*(coap_option *) opt->data)); if (!ret) { return CA_STATUS_FAILED; @@ -1785,6 +1803,7 @@ CAResult_t CAAddBlockSizeOption(coap_pdu_t *pdu, uint16_t sizeType, size_t dataL OIC_LOG(DEBUG, TAG, "IN-CAAddBlockSizeOption"); VERIFY_NON_NULL(pdu, TAG, "pdu"); VERIFY_NON_NULL(options, TAG, "options"); + VERIFY_TRUE((dataLength <= UINT_MAX), TAG, "dataLength"); if (sizeType != COAP_OPTION_SIZE1 && sizeType != COAP_OPTION_SIZE2) { @@ -1793,7 +1812,8 @@ CAResult_t CAAddBlockSizeOption(coap_pdu_t *pdu, uint16_t sizeType, size_t dataL } unsigned char value[BLOCKWISE_OPTION_BUFFER] = { 0 }; - unsigned int optionLength = coap_encode_var_bytes(value, dataLength); + unsigned int optionLength = coap_encode_var_bytes(value, + (unsigned int)dataLength); int ret = coap_insert(options, CACreateNewOptionNode(sizeType, optionLength, (char *) value), @@ -1831,7 +1851,7 @@ bool CAIsPayloadLengthInPduWithBlockSizeOption(coap_pdu_t *pdu, *totalPayloadLen = coap_decode_var_bytes(COAP_OPT_VALUE(option), COAP_OPT_LENGTH(option)); - OIC_LOG_V(DEBUG, TAG, "the total payload length to be received is [%zu]bytes", + OIC_LOG_V(DEBUG, TAG, "the total payload length to be received is [%" PRIuPTR "]bytes", *totalPayloadLen); return true; @@ -1896,16 +1916,16 @@ uint8_t CACheckBlockErrorType(CABlockData_t *currData, coap_block_t *receivedBlo if (receivedBlock->m && blockPayloadLen != (size_t) BLOCK_SIZE(receivedBlock->szx)) { // 413 Error handling of too large entity - if (COAP_MAX_PDU_SIZE < BLOCK_SIZE(receivedBlock->szx) + optionLen) + if (COAP_MAX_PDU_SIZE < ((size_t)BLOCK_SIZE(receivedBlock->szx)) + optionLen) { // buffer size is smaller than received block size OIC_LOG(ERROR, TAG, "error type 4.13"); OIC_LOG(ERROR, TAG, "too large size"); // set the block size to be smaller than COAP_MAX_PDU_SIZE - for (int32_t size = CA_DEFAULT_BLOCK_SIZE; size >= 0; size--) + for (unsigned int size = CA_DEFAULT_BLOCK_SIZE; size >= 0; size--) { - if (COAP_MAX_PDU_SIZE >= BLOCK_SIZE(size) + optionLen) + if (COAP_MAX_PDU_SIZE >= (size_t)BLOCK_SIZE(size) + optionLen) { OIC_LOG_V(ERROR, TAG, "replace sze with %d", size); currData->block2.szx = size; @@ -2028,6 +2048,8 @@ CAData_t* CACreateNewDataSet(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint VERIFY_NON_NULL_RET(pdu, TAG, "pdu", NULL); VERIFY_NON_NULL_RET(pdu->transport_hdr, TAG, "pdu->transport_hdr", NULL); VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL); + VERIFY_TRUE_RET((pdu->transport_hdr->udp.token_length <= UINT8_MAX), TAG, + "pdu->transport_hdr->udp.token_length", NULL); CARequestInfo_t* requestInfo = NULL; CAResponseInfo_t* responseInfo = NULL; @@ -2035,7 +2057,7 @@ CAData_t* CACreateNewDataSet(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint uint32_t code = pdu->transport_hdr->udp.code; if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code) { - CAInfo_t responseData = { .tokenLength = pdu->transport_hdr->udp.token_length }; + CAInfo_t responseData = { .tokenLength = (uint8_t)pdu->transport_hdr->udp.token_length }; responseData.token = (CAToken_t) OICMalloc(responseData.tokenLength); if (!responseData.token) { @@ -2055,7 +2077,7 @@ CAData_t* CACreateNewDataSet(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint } else { - CAInfo_t requestData = { .tokenLength = pdu->transport_hdr->udp.token_length }; + CAInfo_t requestData = { .tokenLength = (uint8_t)pdu->transport_hdr->udp.token_length }; requestData.token = (CAToken_t) OICMalloc(requestData.tokenLength); if (!requestData.token) { @@ -2249,7 +2271,7 @@ CAResult_t CAHandleBlockErrorResponse(coap_block_t *block, uint16_t blockType, return CA_STATUS_OK; } -CAResult_t CAUpdateBlockOptionType(const CABlockDataID_t *blockID, uint8_t blockType) +CAResult_t CAUpdateBlockOptionType(const CABlockDataID_t *blockID, uint16_t blockType) { OIC_LOG(DEBUG, TAG, "IN-UpdateBlockOptionType"); VERIFY_NON_NULL(blockID, TAG, "blockID"); @@ -2274,7 +2296,7 @@ CAResult_t CAUpdateBlockOptionType(const CABlockDataID_t *blockID, uint8_t block return CA_STATUS_FAILED; } -uint8_t CAGetBlockOptionType(const CABlockDataID_t *blockID) +uint16_t CAGetBlockOptionType(const CABlockDataID_t *blockID) { OIC_LOG(DEBUG, TAG, "IN-GetBlockOptionType"); VERIFY_NON_NULL_RET(blockID, TAG, "blockID", 0); diff --git a/resource/csdk/connectivity/src/caconnectivitymanager.c b/resource/csdk/connectivity/src/caconnectivitymanager.c index c7d1dd2..6c870ed 100644 --- a/resource/csdk/connectivity/src/caconnectivitymanager.c +++ b/resource/csdk/connectivity/src/caconnectivitymanager.c @@ -288,7 +288,7 @@ void CADestroyToken(CAToken_t token) OIC_LOG(DEBUG, TAG, "OUT"); } -CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size) +CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, size_t *size) { OIC_LOG(DEBUG, TAG, "CAGetNetworkInformation"); diff --git a/resource/csdk/connectivity/src/cainterfacecontroller.c b/resource/csdk/connectivity/src/cainterfacecontroller.c index c54547d..44245d8 100644 --- a/resource/csdk/connectivity/src/cainterfacecontroller.c +++ b/resource/csdk/connectivity/src/cainterfacecontroller.c @@ -52,7 +52,7 @@ static CAConnectivityHandler_t *g_adapterHandler = NULL; -static uint32_t g_numberOfAdapters = 0; +static size_t g_numberOfAdapters = 0; static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL; @@ -77,9 +77,9 @@ typedef struct CANetworkCallback_t { } CANetworkCallback_t; -static int CAGetAdapterIndex(CATransportAdapter_t cType) +static size_t CAGetAdapterIndex(CATransportAdapter_t cType) { - for (uint32_t index=0 ; index < g_numberOfAdapters ; index++) + for (size_t index = 0 ; index < g_numberOfAdapters ; index++) { if (cType == g_adapterHandler[index].cType ) { @@ -105,7 +105,7 @@ static void CARegisterCallback(CAConnectivityHandler_t handler) OIC_LOG(ERROR, TAG, "connectivity handler is not enough to be used!"); return; } - uint32_t numberofAdapters = g_numberOfAdapters + 1; + size_t numberofAdapters = g_numberOfAdapters + 1; CAConnectivityHandler_t *adapterHandler = OICRealloc(g_adapterHandler, (numberofAdapters) * sizeof(*adapterHandler)); if (NULL == adapterHandler) @@ -392,7 +392,7 @@ CAResult_t CAStartAdapter(CATransportAdapter_t transportType) { OIC_LOG_V(DEBUG, TAG, "Start the adapter of CAConnectivityType[%d]", transportType); - int index = CAGetAdapterIndex(transportType); + size_t index = CAGetAdapterIndex(transportType); if (0 > index) { OIC_LOG(ERROR, TAG, "unknown connectivity type!"); @@ -412,7 +412,7 @@ void CAStopAdapter(CATransportAdapter_t transportType) { OIC_LOG_V(DEBUG, TAG, "Stop the adapter of CATransportType[%d]", transportType); - int index = CAGetAdapterIndex(transportType); + size_t index = CAGetAdapterIndex(transportType); if (0 > index) { OIC_LOG(ERROR, TAG, "unknown transport type!"); @@ -425,7 +425,7 @@ void CAStopAdapter(CATransportAdapter_t transportType) } } -CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size) +CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, size_t *size) { VERIFY_NON_NULL(info, TAG, "info is null"); VERIFY_NON_NULL(size, TAG, "size is null"); @@ -436,7 +436,7 @@ CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size) OIC_LOG(ERROR, TAG, "Out of memory!"); return CA_MEMORY_ALLOC_FAILED; } - uint32_t *tempSize =(uint32_t*) OICCalloc(g_numberOfAdapters, sizeof(*tempSize)); + size_t *tempSize = (size_t*)OICCalloc(g_numberOfAdapters, sizeof(*tempSize)); if (!tempSize) { OIC_LOG(ERROR, TAG, "Out of memory!"); @@ -446,7 +446,7 @@ CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size) CAResult_t res = CA_STATUS_FAILED; size_t resSize = 0; - for (uint32_t index = 0; index < g_numberOfAdapters; index++) + for (size_t index = 0; index < g_numberOfAdapters; index++) { if (g_adapterHandler[index].GetnetInfo != NULL) { @@ -469,7 +469,7 @@ CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size) } } - OIC_LOG_V(DEBUG, TAG, "network info total size is %zu!", resSize); + OIC_LOG_V(DEBUG, TAG, "network info total size is %" PRIuPTR "!", resSize); if (resSize == 0) { @@ -494,7 +494,7 @@ CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size) *info = resInfo; *size = resSize; - for (uint32_t index = 0; index < g_numberOfAdapters; index++) + for (size_t index = 0; index < g_numberOfAdapters; index++) { // check information if (tempSize[index] == 0) @@ -521,7 +521,7 @@ CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size) // memory error label. memory_error_exit: - for (uint32_t index = 0; index < g_numberOfAdapters; index++) + for (size_t index = 0; index < g_numberOfAdapters; index++) { OICFree(tempInfo[index]); tempInfo[index] = NULL; @@ -545,7 +545,7 @@ CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data, uin } CATransportAdapter_t requestedAdapter = endpoint->adapter ? endpoint->adapter : CA_ALL_ADAPTERS; - for (uint32_t i = 0; i < u_arraylist_length(list); i++) + for (size_t i = 0; i < u_arraylist_length(list); i++) { void* ptrType = u_arraylist_get(list, i); @@ -560,7 +560,7 @@ CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data, uin continue; } - int index = CAGetAdapterIndex(connType); + size_t index = CAGetAdapterIndex(connType); if (-1 == index) { @@ -576,7 +576,7 @@ CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data, uin sentDataLen = g_adapterHandler[index].sendData(endpoint, data, length, dataType); } - if (sentDataLen != (int32_t)length) + if (sentDataLen != length) { OIC_LOG(ERROR, TAG, "error in sending data. Error will be reported in adapter"); #ifdef SINGLE_THREAD @@ -619,7 +619,7 @@ CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, u continue; } - int index = CAGetAdapterIndex(connType); + size_t index = CAGetAdapterIndex(connType); if (0 > index) { OIC_LOG(ERROR, TAG, "unknown connectivity type!"); @@ -677,7 +677,7 @@ CAResult_t CAStartListeningServerAdapters() CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType; - int index = CAGetAdapterIndex(connType); + size_t index = CAGetAdapterIndex(connType); if (0 > index) { OIC_LOG(ERROR, TAG, "unknown connectivity type!"); @@ -720,7 +720,7 @@ CAResult_t CAStopListeningServerAdapters() CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType; - int index = CAGetAdapterIndex(connType); + size_t index = CAGetAdapterIndex(connType); if (0 > index) { OIC_LOG(ERROR, TAG, "unknown connectivity type!"); @@ -760,7 +760,7 @@ CAResult_t CAStartDiscoveryServerAdapters() CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType; - int index = CAGetAdapterIndex(connType); + size_t index = CAGetAdapterIndex(connType); if (0 > index) { OIC_LOG(DEBUG, TAG, "unknown connectivity type!"); @@ -800,7 +800,7 @@ bool CAIsLocalEndpoint(const CAEndpoint_t *ep) void CATerminateAdapters() { - for (uint32_t index = 0; index < g_numberOfAdapters; index++) + for (size_t index = 0; index < g_numberOfAdapters; index++) { if (g_adapterHandler[index].terminate != NULL) { @@ -823,7 +823,7 @@ CAResult_t CAReadData() return CA_STATUS_FAILED; } - uint8_t i = 0; + size_t i = 0; for (i = 0; i < u_arraylist_length(list); i++) { void *ptrType = u_arraylist_get(list, i); @@ -835,7 +835,7 @@ CAResult_t CAReadData() CATransportAdapter_t connType = *(CATransportAdapter_t *) ptrType; - int index = CAGetAdapterIndex(connType); + size_t index = CAGetAdapterIndex(connType); if (0 > index) { OIC_LOG(DEBUG, TAG, "unknown connectivity type!"); diff --git a/resource/csdk/connectivity/src/camessagehandler.c b/resource/csdk/connectivity/src/camessagehandler.c index f7e4b16..68966d7 100644 --- a/resource/csdk/connectivity/src/camessagehandler.c +++ b/resource/csdk/connectivity/src/camessagehandler.c @@ -1173,10 +1173,9 @@ void CATerminateMessageHandler() #ifndef SINGLE_THREAD CATransportAdapter_t connType; u_arraylist_t *list = CAGetSelectedNetworkList(); - uint32_t length = u_arraylist_length(list); + size_t length = u_arraylist_length(list); - uint32_t i = 0; - for (i = 0; i < length; i++) + for (size_t i = 0; i < length; i++) { void* ptrType = u_arraylist_get(list, i); @@ -1253,7 +1252,7 @@ static void CALogPayloadInfo(CAInfo_t *info) if (info->payload) { - OIC_LOG_V(DEBUG, TAG, "payload: %p(%zu)", info->payload, + OIC_LOG_V(DEBUG, TAG, "payload: %p(%" PRIuPTR ")", info->payload, info->payloadSize); } diff --git a/resource/csdk/connectivity/src/canetworkconfigurator.c b/resource/csdk/connectivity/src/canetworkconfigurator.c index 49393bd..bb2cf4e 100644 --- a/resource/csdk/connectivity/src/canetworkconfigurator.c +++ b/resource/csdk/connectivity/src/canetworkconfigurator.c @@ -183,8 +183,8 @@ CAResult_t CARemoveNetworkType(CATransportAdapter_t transportType) return CA_STATUS_FAILED; } - uint32_t selectedNetworkLength = u_arraylist_length(g_selectedNetworkList); - for (uint32_t index = 0; index < selectedNetworkLength; index++) + size_t selectedNetworkLength = u_arraylist_length(g_selectedNetworkList); + for (size_t index = 0; index < selectedNetworkLength; index++) { void* ptrType = u_arraylist_get(g_selectedNetworkList, index); if (NULL == ptrType) @@ -283,7 +283,7 @@ CATransportAdapter_t CAGetSelectedNetwork() return CASelectedNetwork; } -CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, uint32_t *size) +CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, size_t *size) { OIC_LOG(DEBUG, TAG, "get network information."); diff --git a/resource/csdk/connectivity/src/caprotocolmessage.c b/resource/csdk/connectivity/src/caprotocolmessage.c index c06c58a..5060163 100644 --- a/resource/csdk/connectivity/src/caprotocolmessage.c +++ b/resource/csdk/connectivity/src/caprotocolmessage.c @@ -138,14 +138,14 @@ coap_pdu_t *CAGeneratePDU(uint32_t code, const CAInfo_t *info, const CAEndpoint_ { OIC_LOG_V(DEBUG, TAG, "uri : %s", info->resourceUri); - uint32_t length = strlen(info->resourceUri); + size_t length = strlen(info->resourceUri); if (CA_MAX_URI_LENGTH < length) { OIC_LOG(ERROR, TAG, "URI len err"); return NULL; } - uint32_t uriLength = length + sizeof(COAP_URI_HEADER); + size_t uriLength = length + sizeof(COAP_URI_HEADER); char *coapUri = (char *) OICCalloc(1, uriLength); if (NULL == coapUri) { @@ -259,10 +259,12 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info, VERIFY_NON_NULL_RET(info, TAG, "info", NULL); VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", NULL); VERIFY_NON_NULL_RET(transport, TAG, "transport", NULL); + VERIFY_TRUE_RET((info->payloadSize <= COAP_MAX_PDU_SIZE), TAG, + "info->payloadSize", NULL); - unsigned int length = COAP_MAX_PDU_SIZE; + size_t length = COAP_MAX_PDU_SIZE; #ifdef WITH_TCP - unsigned int msgLength = 0; + size_t msgLength = 0; if (CAIsSupportedCoAPOverTCP(endpoint->adapter)) { if (options) @@ -286,8 +288,8 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info, } msgLength += optLength; prevOptNumber = curOptNumber; - OIC_LOG_V(DEBUG, TAG, "curOptNumber[%d], prevOptNumber[%d], optValueLen[%zu], " - "optLength[%zu], msgLength[%d]", + OIC_LOG_V(DEBUG, TAG, "curOptNumber[%d], prevOptNumber[%d], optValueLen[%" PRIuPTR "], " + "optLength[%" PRIuPTR "], msgLength[%" PRIuPTR "]", curOptNumber, prevOptNumber, optValueLen, optLength, msgLength); } } @@ -296,7 +298,14 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info, { msgLength = msgLength + info->payloadSize + PAYLOAD_MARKER; } - *transport = coap_get_tcp_header_type_from_size(msgLength); + + if (msgLength > UINT_MAX) + { + OIC_LOG(ERROR, TAG, "Message length too large."); + return NULL; + } + + *transport = coap_get_tcp_header_type_from_size((unsigned int)msgLength); length = msgLength + coap_get_tcp_header_length_for_transport(*transport) + info->tokenLength; } @@ -306,7 +315,9 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info, *transport = COAP_UDP; } - coap_pdu_t *pdu = coap_new_pdu2(*transport, length); + coap_pdu_t *pdu = coap_pdu_init2(0, 0, + ntohs(COAP_INVALID_TID), + length, *transport); if (NULL == pdu) { @@ -314,13 +325,13 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info, return NULL; } - OIC_LOG_V(DEBUG, TAG, "transport type: %d, payload size: %zu", + OIC_LOG_V(DEBUG, TAG, "transport type: %d, payload size: %" PRIuPTR, *transport, info->payloadSize); #ifdef WITH_TCP if (CAIsSupportedCoAPOverTCP(endpoint->adapter)) { - coap_add_length(pdu, *transport, msgLength); + coap_add_length(pdu, *transport, (unsigned int)msgLength); } else #endif @@ -393,10 +404,11 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info, OIC_LOG_V(DEBUG, TAG, "[%d] pdu length after option", pdu->length); - if (NULL != info->payload && 0 < info->payloadSize) + if ((NULL != info->payload) && (0 < info->payloadSize)) { OIC_LOG(DEBUG, TAG, "payload is added"); - coap_add_data(pdu, info->payloadSize, (const unsigned char *) info->payload); + coap_add_data(pdu, (unsigned int)info->payloadSize, + (const unsigned char*)info->payload); } return pdu; @@ -1009,7 +1021,7 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint, if (optionResult[0] != '\0') { - OIC_LOG_V(DEBUG, TAG, "URL length:%zu", strlen(optionResult)); + OIC_LOG_V(DEBUG, TAG, "URL length:%" PRIuPTR, strlen(optionResult)); outInfo->resourceUri = OICStrdup(optionResult); if (!outInfo->resourceUri) { diff --git a/resource/csdk/connectivity/src/caretransmission.c b/resource/csdk/connectivity/src/caretransmission.c index 0f78f31..7cbcd30 100644 --- a/resource/csdk/connectivity/src/caretransmission.c +++ b/resource/csdk/connectivity/src/caretransmission.c @@ -93,6 +93,7 @@ typedef struct } CARetransmissionData_t; static const uint64_t USECS_PER_SEC = 1000000; +static const uint64_t USECS_PER_MSEC = 1000; static const uint64_t MSECS_PER_SEC = 1000; #ifndef SINGLE_THREAD @@ -152,8 +153,8 @@ static bool CACheckTimeout(uint64_t currentTime, CARetransmissionData_t *retData { #ifndef SINGLE_THREAD // #1. calculate timeout - uint32_t milliTimeoutValue = retData->timeout * 0.001; - uint64_t timeout = ((uint64_t) milliTimeoutValue << retData->triedCount) * MSECS_PER_SEC; + uint64_t milliTimeoutValue = retData->timeout / USECS_PER_MSEC; + uint64_t timeout = (milliTimeoutValue << retData->triedCount) * USECS_PER_MSEC; if (currentTime >= retData->timeStamp + timeout) { @@ -186,10 +187,9 @@ static void CACheckRetransmissionList(CARetransmission_t *context) // mutex lock oc_mutex_lock(context->threadMutex); - uint32_t i = 0; - uint32_t len = u_arraylist_length(context->dataList); + size_t len = u_arraylist_length(context->dataList); - for (i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { CARetransmissionData_t *retData = u_arraylist_get(context->dataList, i); @@ -443,11 +443,10 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context, // mutex lock oc_mutex_lock(context->threadMutex); - uint32_t i = 0; - uint32_t len = u_arraylist_length(context->dataList); + size_t len = u_arraylist_length(context->dataList); // #3. add data into list - for (i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { CARetransmissionData_t *currData = u_arraylist_get(context->dataList, i); @@ -523,11 +522,9 @@ CAResult_t CARetransmissionReceivedData(CARetransmission_t *context, // mutex lock oc_mutex_lock(context->threadMutex); - uint32_t len = u_arraylist_length(context->dataList); + size_t len = u_arraylist_length(context->dataList); - // find index - uint32_t i; - for (i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { CARetransmissionData_t *retData = (CARetransmissionData_t *) u_arraylist_get( context->dataList, i); @@ -639,8 +636,8 @@ CAResult_t CARetransmissionDestroy(CARetransmission_t *context) OIC_LOG(DEBUG, TAG, "retransmission context destroy.."); oc_mutex_lock(context->threadMutex); - uint32_t len = u_arraylist_length(context->dataList); - for (uint32_t i = 0; i < len; i++) + size_t len = u_arraylist_length(context->dataList); + for (size_t i = 0; i < len; i++) { CARetransmissionData_t *data = u_arraylist_get(context->dataList, i); if (NULL == data) diff --git a/resource/csdk/connectivity/test/ca_api_unittest.cpp b/resource/csdk/connectivity/test/ca_api_unittest.cpp index cfbe602..e234da0 100755 --- a/resource/csdk/connectivity/test/ca_api_unittest.cpp +++ b/resource/csdk/connectivity/test/ca_api_unittest.cpp @@ -402,7 +402,7 @@ TEST_F(CATests, HandlerRequestResponseTest) // CAGetNetworkInformation TC TEST_F (CATests, GetNetworkInformationTest) { - uint32_t tempSize = 0; + size_t tempSize = 0; CAEndpoint_t *tempInfo = NULL; EXPECT_EQ(CA_STATUS_OK, CASelectNetwork(CA_ADAPTER_IP)); @@ -410,7 +410,7 @@ TEST_F (CATests, GetNetworkInformationTest) // @todo: if this api is supported on windows platform, it should be changed. #if !defined(_WIN32) - for (uint32_t index = 0; index < tempSize; index++) + for (size_t index = 0; index < tempSize; index++) { EXPECT_TRUE(tempInfo[index].adapter != 0); EXPECT_TRUE(strlen(tempInfo[index].addr) != 0); diff --git a/resource/csdk/connectivity/test/ssladapter_test.cpp b/resource/csdk/connectivity/test/ssladapter_test.cpp index 15fec8c..d086a5a 100644 --- a/resource/csdk/connectivity/test/ssladapter_test.cpp +++ b/resource/csdk/connectivity/test/ssladapter_test.cpp @@ -18,6 +18,7 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include #include "gtest/gtest.h" #include "time.h" @@ -83,6 +84,7 @@ #define dummyHandler 0xF123 #define SERVER_PORT 4433 +#define SERVER_PORT_STRING "4433" #define SERVER_NAME "localhost" #define GET_REQUEST "GET / HTTP/1.0\r\n\r\n" @@ -966,40 +968,42 @@ static void error(const char *msg) exit(0); } -static int sockfd, newsockfd; +static CASocketFd_t sockfd, newsockfd; static void socketConnect() { - int portno; - struct sockaddr_in serv_addr; - struct hostent *server; + struct addrinfo* addressInfo = NULL; + struct addrinfo hints; + + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_INET; - portno = SERVER_PORT; sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error("ERROR opening socket"); - server = gethostbyname(SERVER_NAME); - if (server == NULL) { + + int result = getaddrinfo(SERVER_NAME, SERVER_PORT_STRING, &hints, &addressInfo); + if (0 != result) + { fprintf(stderr,"ERROR, no such host\n"); exit(0); } - //memset((char *) &serv_addr, sizeof(serv_addr)); - memset((void*)&serv_addr, 0, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - memcpy((char *)server->h_addr, - (char *)&serv_addr.sin_addr.s_addr, - server->h_length); - serv_addr.sin_port = htons(portno); - if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) + + if (connect(sockfd, addressInfo->ai_addr, (int)addressInfo->ai_addrlen) < 0) + { error("ERROR connecting"); + } + + freeaddrinfo(addressInfo); } static ssize_t CATCPPacketSendCB(CAEndpoint_t *, const void *buf, size_t buflen) { - int n; - n = write(sockfd, buf, buflen); + int n = send(sockfd, (const char*)buf, (int)buflen, 0); if (n < 0) - error("ERROR writing to socket"); + { + error("ERROR writing to socket"); + } return n; } @@ -1014,12 +1018,12 @@ static void PacketReceive(unsigned char *data, int * datalen) { int n; char buffer[2048] = {'\0'}; - n = read(sockfd, buffer, 5); + n = recv(sockfd, buffer, 5, 0); if ((buffer[0] == 0x16 || buffer[0] == 0x14 || buffer[0] == 0x17 || buffer[0] == 0x15) && buffer[1] == 0x03 && buffer[2] == 0x03) { int tlslen = (unsigned char)buffer[3] * 0x100 + (unsigned char)buffer[4]; - n = read(sockfd, buffer + 5, tlslen); + n = recv(sockfd, buffer + 5, tlslen, 0); } if (n < 0) @@ -1031,7 +1035,7 @@ static void PacketReceive(unsigned char *data, int * datalen) static void socketClose() { - close(sockfd); + OC_CLOSE_SOCKET(sockfd); } static void infoCallback_that_loads_x509(PkiInfo_t * inf) @@ -1076,7 +1080,7 @@ static void socketOpen_server() static ssize_t CATCPPacketSendCB_server(CAEndpoint_t *, const void *buf, size_t buflen) { int n; - n = write(newsockfd,buf,buflen); + n = send(newsockfd, (const char*)buf, (int)buflen, 0); if (n < 0) error("ERROR writing to socket"); return n; @@ -1091,12 +1095,12 @@ static void PacketReceive_server(unsigned char *data, int * datalen) { int n; char buffer[2048] = {'\0'}; - n = read(newsockfd, buffer, 5); + n = recv(newsockfd, buffer, 5, 0); if (buffer[0] == 0x16 || buffer[0] == 0x14 || buffer[0] == 0x17 || buffer[0] == 0x15) { int tlslen = (unsigned char)buffer[3] * 0x100 + (unsigned char)buffer[4]; - n = read(newsockfd, buffer + 5, tlslen); + n = recv(newsockfd, buffer + 5, tlslen, 0); } if (n < 0) @@ -1108,8 +1112,8 @@ static void PacketReceive_server(unsigned char *data, int * datalen) static void socketClose_server() { - close(newsockfd); - close(sockfd); + OC_CLOSE_SOCKET(newsockfd); + OC_CLOSE_SOCKET(sockfd); } static void clutch(bool * list) @@ -2000,11 +2004,11 @@ unsigned char predictedClientHello[] = { 0x00, 0x00, 0x00, 0x17, 0x00, 0x00 }; static unsigned char controlBuf[sizeof(predictedClientHello)]; -static char controlBufLen = 0; +static size_t controlBufLen = 0; static ssize_t CATCPPacketSendCB_forInitHsTest(CAEndpoint_t *, const void * buf, size_t buflen) { int n; - n = write(sockfd, buf, buflen); + n = send(sockfd, (const char*)buf, (int)buflen, 0); if (n < 0) error("ERROR writing to socket"); @@ -3224,7 +3228,7 @@ TEST(TLSAdaper, Test_ParseChain) int errNum; mbedtls_x509_crt crt; mbedtls_x509_crt_init(&crt); - int ret = ParseChain(&crt, certChain, certChainLen, &errNum); + size_t ret = ParseChain(&crt, certChain, certChainLen, &errNum); mbedtls_x509_crt_free(&crt); EXPECT_EQ(10, ret + errNum); diff --git a/resource/csdk/logger/include/logger.h b/resource/csdk/logger/include/logger.h index 9daf251..1f83f98 100644 --- a/resource/csdk/logger/include/logger.h +++ b/resource/csdk/logger/include/logger.h @@ -23,6 +23,7 @@ #define IOTIVITY_VERSION "1.3.0" +#include #include #include #include diff --git a/resource/csdk/stack/include/internal/ocstackinternal.h b/resource/csdk/stack/include/internal/ocstackinternal.h index 858dbc7..d21fcc0 100644 --- a/resource/csdk/stack/include/internal/ocstackinternal.h +++ b/resource/csdk/stack/include/internal/ocstackinternal.h @@ -342,7 +342,7 @@ void OCDeleteResourceAttributes(OCAttribute *rsrcAttributes); */ void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCResource *res, uint16_t securePort, bool isVirtual, - void *networkInfo, uint32_t infoSize, + void *networkInfo, size_t infoSize, const OCDevAddr *devAddr); #else /** @@ -359,7 +359,7 @@ void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCR */ void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCResource *res, uint16_t securePort, bool isVirtual, - void *networkInfo, uint32_t infoSize, + void *networkInfo, size_t infoSize, const OCDevAddr *devAddr, uint16_t tcpPort); #endif #ifdef __cplusplus diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp index 4ea4de1..5caedf7 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp @@ -19,6 +19,7 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "iotivity_config.h" +#include #include #include #include diff --git a/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp b/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp index 776a695..822e06b 100644 --- a/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp +++ b/resource/csdk/stack/samples/linux/secure/occlientdirectpairing.cpp @@ -19,6 +19,7 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "iotivity_config.h" +#include #include #include #include diff --git a/resource/csdk/stack/src/ocpayload.c b/resource/csdk/stack/src/ocpayload.c index 8a70166..ce389aa 100644 --- a/resource/csdk/stack/src/ocpayload.c +++ b/resource/csdk/stack/src/ocpayload.c @@ -1766,7 +1766,7 @@ void OCResourcePayloadAddNewEndpoint(OCResourcePayload* payload, OCEndpointPaylo static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t securePort, bool isVirtual, CAEndpoint_t *networkInfo, - uint32_t infoSize, const OCDevAddr *devAddr + size_t infoSize, const OCDevAddr *devAddr #ifndef TCP_ADAPTER ) #else @@ -1896,7 +1896,7 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP OCEndpointPayload *lastNode = pl->eps; if ((OC_ADAPTER_IP | OC_ADAPTER_TCP) & (devAddr->adapter)) { - for (uint32_t i = 0; i < infoSize; i++) + for (size_t i = 0; i < infoSize; i++) { CAEndpoint_t *info = networkInfo + i; @@ -1984,7 +1984,7 @@ void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource #ifndef TCP_ADAPTER void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload* payload, const OCResource* res, uint16_t securePort, bool isVirtual, - void *networkInfo, uint32_t infoSize, + void *networkInfo, size_t infoSize, const OCDevAddr *devAddr) { OCDiscoveryPayloadAddNewResource(payload, @@ -1995,7 +1995,7 @@ void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload* payload, const OCR #else void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload* payload, const OCResource* res, uint16_t securePort, bool isVirtual, - void *networkInfo, uint32_t infoSize, + void *networkInfo, size_t infoSize, const OCDevAddr *devAddr, uint16_t tcpPort) { OCDiscoveryPayloadAddNewResource(payload, diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c index 9120d0b..c16d8a1 100755 --- a/resource/csdk/stack/src/ocresource.c +++ b/resource/csdk/stack/src/ocresource.c @@ -78,7 +78,7 @@ static OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr, OCDiscoveryPayload *payload, OCDevAddr *endpoint, CAEndpoint_t *networkInfo, - uint32_t infoSize); + size_t infoSize); //----------------------------------------------------------------------------- // Default resource entity handler function @@ -886,7 +886,7 @@ OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr, OCDiscoveryPayload *payload, OCDevAddr *devAddr, CAEndpoint_t *networkInfo, - uint32_t infoSize) + size_t infoSize) { if (!resourcePtr || !payload) { @@ -1428,7 +1428,7 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource char *resourceTypeQuery = NULL; CAEndpoint_t *networkInfo = NULL; - uint32_t infoSize = 0; + size_t infoSize = 0; CAResult_t caResult = CAGetNetworkInformation(&networkInfo, &infoSize); if (CA_STATUS_FAILED == caResult) diff --git a/resource/csdk/stack/src/oickeepalive.c b/resource/csdk/stack/src/oickeepalive.c index 89a69ca..91b0147 100644 --- a/resource/csdk/stack/src/oickeepalive.c +++ b/resource/csdk/stack/src/oickeepalive.c @@ -186,7 +186,7 @@ OCStackResult HandleKeepAliveResponse(const CAEndpoint_t *endPoint, * @param[out] index index of array list. * @return KeepAlive entry to send ping message. */ -static KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, uint32_t *index); +static KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, size_t *index); /** * Add keepalive entry. @@ -405,7 +405,7 @@ OCStackResult SendKeepAliveResponse(OCServerRequest *request, CAEndpoint_t endpoint = {.adapter = CA_DEFAULT_ADAPTER}; CopyDevAddrToEndpoint(&request->devAddr, &endpoint); - uint32_t index = 0; + size_t index = 0; KeepAliveEntry_t *entry = GetEntryFromEndpoint(&endpoint, &index); int64_t interval = (entry) ? entry->interval : 0; @@ -458,7 +458,7 @@ OCEntityHandlerResult HandleKeepAlivePOSTRequest(OCServerRequest *request, CAEndpoint_t endpoint = { .adapter = CA_DEFAULT_ADAPTER }; CopyDevAddrToEndpoint(&request->devAddr, &endpoint); - uint32_t index = 0; + size_t index = 0; KeepAliveEntry_t *entry = GetEntryFromEndpoint(&endpoint, &index); if (!entry) { @@ -496,7 +496,7 @@ OCStackResult HandleKeepAliveResponse(const CAEndpoint_t *endPoint, OIC_LOG(DEBUG, TAG, "HandleKeepAliveResponse IN"); // Get entry from KeepAlive table. - uint32_t index = 0; + size_t index = 0; KeepAliveEntry_t *entry = GetEntryFromEndpoint(endPoint, &index); if (!entry) { @@ -555,9 +555,9 @@ void ProcessKeepAlive() return; } - uint32_t len = u_arraylist_length(g_keepAliveConnectionTable); + size_t len = u_arraylist_length(g_keepAliveConnectionTable); - for (uint32_t i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { KeepAliveEntry_t *entry = (KeepAliveEntry_t *)u_arraylist_get(g_keepAliveConnectionTable, i); @@ -622,7 +622,7 @@ void IncreaseInterval(KeepAliveEntry_t *entry) { VERIFY_NON_NULL_NR(entry, FATAL); - OIC_LOG_V(DEBUG, TAG, "Total interval counts: %zu", entry->intervalSize); + OIC_LOG_V(DEBUG, TAG, "Total interval counts: %" PRIuPTR, entry->intervalSize); if (entry->intervalSize > (size_t)entry->currIndex + 1) { entry->currIndex++; @@ -699,7 +699,7 @@ OCStackApplicationResult PingRequestCallback(void* ctx, OCDoHandle handle, return OC_STACK_DELETE_TRANSACTION; } -KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, uint32_t *index) +KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, size_t *index) { if (!g_keepAliveConnectionTable) { @@ -707,9 +707,9 @@ KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, uint32_t *i return NULL; } - uint32_t len = u_arraylist_length(g_keepAliveConnectionTable); + size_t len = u_arraylist_length(g_keepAliveConnectionTable); - for (uint32_t i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { KeepAliveEntry_t *entry = (KeepAliveEntry_t *)u_arraylist_get(g_keepAliveConnectionTable, i); @@ -788,7 +788,7 @@ OCStackResult RemoveKeepAliveEntry(const CAEndpoint_t *endpoint) { VERIFY_NON_NULL(endpoint, FATAL, OC_STACK_INVALID_PARAM); - uint32_t index = 0; + size_t index = 0; KeepAliveEntry_t *entry = GetEntryFromEndpoint(endpoint, &index); if (!entry) { diff --git a/resource/csdk/stack/test/stacktests.cpp b/resource/csdk/stack/test/stacktests.cpp index b8f5129..c7e5715 100644 --- a/resource/csdk/stack/test/stacktests.cpp +++ b/resource/csdk/stack/test/stacktests.cpp @@ -2529,11 +2529,11 @@ TEST_F(OCDiscoverTests, DISABLED_DiscoverResourceWithInvalidQueries) TEST(StackZoneId, getZoneId) { - uint32_t tempSize = 0; + size_t tempSize = 0; CAEndpoint_t *tempInfo = NULL; CAGetNetworkInformation(&tempInfo, &tempSize); - for (uint32_t i = 0; i < tempSize; i++) + for (size_t i = 0; i < tempSize; i++) { char *zoneId = NULL; EXPECT_EQ(OC_STACK_OK, OCGetLinkLocalZoneId(tempInfo[i].ifindex, &zoneId)); diff --git a/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h b/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h index 46b9738..a20ac33 100755 --- a/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h +++ b/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h @@ -170,16 +170,16 @@ private: } CAEndpoint_t *tempInfo = NULL; - uint32_t tempSize = 0; + size_t tempSize = 0; CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize); - if (CA_STATUS_OK != res || NULL == tempInfo || 0 >= tempSize) + if (CA_STATUS_OK != res || NULL == tempInfo || 0 == tempSize) { free(tempInfo); return false; } - for (uint32_t index = 0; index < tempSize; index++) + for (size_t index = 0; index < tempSize; index++) { if (CA_ADAPTER_IP == tempInfo[index].adapter) { diff --git a/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp b/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp index 0dcd6ef..930fc70 100755 --- a/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp +++ b/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp @@ -144,16 +144,16 @@ private: } CAEndpoint_t *tempInfo = NULL; - uint32_t tempSize = 0; + size_t tempSize = 0; CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize); - if (CA_STATUS_OK != res || NULL == tempInfo || 0 >= tempSize) + if (CA_STATUS_OK != res || NULL == tempInfo || 0 == tempSize) { free(tempInfo); return false; } - for (uint32_t index = 0; index < tempSize; index++) + for (size_t index = 0; index < tempSize; index++) { if (CA_ADAPTER_IP == tempInfo[index].adapter) { diff --git a/service/scene-manager/src/SceneUtils.cpp b/service/scene-manager/src/SceneUtils.cpp index a2330b8..7face9f 100755 --- a/service/scene-manager/src/SceneUtils.cpp +++ b/service/scene-manager/src/SceneUtils.cpp @@ -75,7 +75,7 @@ namespace OIC std::string SceneUtils::getNetAddress() { CAEndpoint_t * netInfo = nullptr; - uint32_t size = 0; + size_t size = 0; CAGetNetworkInformation(&netInfo, &size); if (size == 0) @@ -85,7 +85,7 @@ namespace OIC } std::string address_ipv4 = "", address_ipv6 = ""; - for (uint32_t i = 0; i < size; ++i) + for (size_t i = 0; i < size; ++i) { if (netInfo[i].adapter == CATransportAdapter_t::CA_ADAPTER_IP) { -- 2.7.4