diff --git a/library.properties b/library.properties index 7018367..a7836cd 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AzureIoTUtility -version=1.3.9 +version=1.5.0 author=Microsoft maintainer=Microsoft sentence=Azure C shared utility library for Arduino. For the Arduino MKR1000 or Zero and WiFi Shield 101, Adafruit Huzzah and Feather M0, or SparkFun Thing. diff --git a/src/AzureIoTUtility.h b/src/AzureIoTUtility.h index 002cff0..1e198e6 100644 --- a/src/AzureIoTUtility.h +++ b/src/AzureIoTUtility.h @@ -12,6 +12,6 @@ #include "azure_c_shared_utility/tlsio.h" #include "azure_c_shared_utility/xlogging.h" -#define AzureIoTUtilityVersion "1.3.9" +#define AzureIoTUtilityVersion "1.5.0" #endif //AZUREIOTUTILITY_H diff --git a/src/adapters/sslClient_arduino.cpp b/src/adapters/sslClient_arduino.cpp index ffeda06..d98e3ba 100644 --- a/src/adapters/sslClient_arduino.cpp +++ b/src/adapters/sslClient_arduino.cpp @@ -31,13 +31,12 @@ uint8_t sslClient_connected(void) return (uint8_t)sslClient.connected(); } -int sslClient_connect(uint32_t ipAddress, uint16_t port) +int sslClient_connect(const char* name, uint16_t port) { #ifdef ARDUINO_ARCH_ESP8266 sslClient.setTrustAnchors(&cert); #endif - IPAddress ip = IPAddress(ipAddress); - return (int)sslClient.connect(ip, port); + return (int)sslClient.connect(name, port); } void sslClient_stop(void) diff --git a/src/adapters/sslClient_arduino.h b/src/adapters/sslClient_arduino.h index a53b5e6..0b9af66 100644 --- a/src/adapters/sslClient_arduino.h +++ b/src/adapters/sslClient_arduino.h @@ -17,7 +17,7 @@ extern "C" { MOCKABLE_FUNCTION(, void, sslClient_setTimeout, unsigned long, timeout); MOCKABLE_FUNCTION(, uint8_t, sslClient_connected); -MOCKABLE_FUNCTION(, int, sslClient_connect, uint32_t, ipAddress, uint16_t, port); +MOCKABLE_FUNCTION(, int, sslClient_connect, const char*, name, uint16_t, port); MOCKABLE_FUNCTION(, void, sslClient_stop); MOCKABLE_FUNCTION(, size_t, sslClient_write, const uint8_t*, buf, size_t, size); MOCKABLE_FUNCTION(, size_t, sslClient_print, const char*, str); diff --git a/src/adapters/tlsio_arduino.c b/src/adapters/tlsio_arduino.c index 88aeefa..540e0ad 100644 --- a/src/adapters/tlsio_arduino.c +++ b/src/adapters/tlsio_arduino.c @@ -46,7 +46,6 @@ const size_t WEBSOCKET_HEADER_NO_CERT_PARAM_SIZE = sizeof(WEBSOCKET_HEADER_NO_CE typedef enum TLSIO_STATE_TAG { TLSIO_STATE_CLOSED, - TLSIO_STATE_OPENING_WAITING_DNS, TLSIO_STATE_OPENING_WAITING_SOCKET, TLSIO_STATE_OPENING_WAITING_SSL, TLSIO_STATE_OPEN, @@ -55,8 +54,7 @@ typedef enum TLSIO_STATE_TAG bool is_an_opening_state(TLSIO_STATE state) { - return state == TLSIO_STATE_OPENING_WAITING_DNS || - state == TLSIO_STATE_OPENING_WAITING_SOCKET || + return state == TLSIO_STATE_OPENING_WAITING_SOCKET || state == TLSIO_STATE_OPENING_WAITING_SSL; } @@ -70,7 +68,6 @@ typedef struct TLS_IO_INSTANCE_TAG void* on_open_complete_context; TLSIO_STATE tlsio_state; STRING_HANDLE hostname; - uint32_t remote_addr; uint16_t port; SINGLYLINKEDLIST_HANDLE pending_transmission_list; TLSIO_OPTIONS options; @@ -234,7 +231,6 @@ static CONCRETE_IO_HANDLE tlsio_arduino_create(void* io_create_parameters) result->hostname = NULL; result->port = (uint16_t)tls_io_config->port; result->tlsio_state = TLSIO_STATE_CLOSED; - result->hostname = NULL; result->pending_transmission_list = NULL; tlsio_options_initialize(&result->options, TLSIO_OPTION_BIT_TRUSTED_CERTS); @@ -328,7 +324,7 @@ static int tlsio_arduino_open_async(CONCRETE_IO_HANDLE tls_io, /* Codes_SRS_TLSIO_30_035: [ On tlsio_open success the adapter shall enter TLSIO_STATE_EX_OPENING and return 0. ]*/ // All the real work happens in dowork - tls_io_instance->tlsio_state = TLSIO_STATE_OPENING_WAITING_DNS; + tls_io_instance->tlsio_state = TLSIO_STATE_OPENING_WAITING_SOCKET; result = 0; } } @@ -477,19 +473,6 @@ static void dowork_send(TLS_IO_INSTANCE* tls_io_instance) } } -static void dowork_poll_dns(TLS_IO_INSTANCE* tls_io_instance) -{ - /* Codes_SRS_TLSIO_ARDUINO_21_018: [ The tlsio_arduino_create shall convert the provide hostName to an IP address. ]*/ - if (sslClient_hostByName(STRING_c_str(tls_io_instance->hostname), &(tls_io_instance->remote_addr))) - { - tls_io_instance->tlsio_state = TLSIO_STATE_OPENING_WAITING_SOCKET; - } - else - { - LogError("Host %s not found", STRING_c_str(tls_io_instance->hostname)); - } -} - static void dowork_poll_socket(TLS_IO_INSTANCE* tls_io_instance) { // Nothing to do here @@ -498,7 +481,7 @@ static void dowork_poll_socket(TLS_IO_INSTANCE* tls_io_instance) static void dowork_poll_open_ssl(TLS_IO_INSTANCE* tls_io_instance) { - int connect_success = sslClient_connect(tls_io_instance->remote_addr, tls_io_instance->port); + int connect_success = sslClient_connect(STRING_c_str(tls_io_instance->hostname), tls_io_instance->port); if (connect_success) { /* Codes_SRS_TLSIO_30_080: [ The tlsio_dowork shall establish a TLS connection using the hostName and port provided during tlsio_open. ]*/ @@ -534,10 +517,6 @@ static void tlsio_arduino_dowork(CONCRETE_IO_HANDLE tls_io) /* Codes_SRS_TLSIO_30_075: [ If the adapter is in TLSIO_STATE_EXT_CLOSED then tlsio_dowork shall do nothing. ]*/ // Waiting to be opened, nothing to do break; - case TLSIO_STATE_OPENING_WAITING_DNS: - LogInfo("dowork TLSIO_STATE_OPENING_WAITING_DNS"); - dowork_poll_dns(tls_io_instance); - break; case TLSIO_STATE_OPENING_WAITING_SOCKET: LogInfo("dowork TLSIO_STATE_OPENING_WAITING_SOCKET"); dowork_poll_socket(tls_io_instance); diff --git a/src/adapters/tlsio_mbedtls.c b/src/adapters/tlsio_mbedtls.c index 08592bf..adfd047 100644 --- a/src/adapters/tlsio_mbedtls.c +++ b/src/adapters/tlsio_mbedtls.c @@ -442,6 +442,7 @@ static void mbedtls_uninit(TLS_IO_INSTANCE *tls_io_instance) { // mbedTLS cleanup... mbedtls_ssl_free(&tls_io_instance->ssl); + mbedtls_ssl_session_free(&tls_io_instance->ssn); mbedtls_ssl_config_free(&tls_io_instance->config); mbedtls_x509_crt_free(&tls_io_instance->trusted_certificates_parsed); mbedtls_x509_crt_free(&tls_io_instance->owncert); diff --git a/src/azure_c_shared_utility/buffer.c b/src/azure_c_shared_utility/buffer.c index d74a1c0..ffd1dbe 100644 --- a/src/azure_c_shared_utility/buffer.c +++ b/src/azure_c_shared_utility/buffer.c @@ -540,11 +540,16 @@ int BUFFER_prepend(BUFFER_HANDLE handle1, BUFFER_HANDLE handle2) else { //put b2 ahead of b1: [b2][b1], return b1 - if (b2->size ==0) + if (b2->size == 0) { // do nothing result = 0; } + else if (b1->size + b2->size < b2->size) + { + LogError("Failure: size_t overflow."); + result = MU_FAILURE; + } else { // b2->size != 0 diff --git a/src/azure_c_shared_utility/constbuffer_array_batcher.c b/src/azure_c_shared_utility/constbuffer_array_batcher.c index a127ef9..bf31504 100644 --- a/src/azure_c_shared_utility/constbuffer_array_batcher.c +++ b/src/azure_c_shared_utility/constbuffer_array_batcher.c @@ -72,7 +72,8 @@ CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDL } /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_007: [ constbuffer_array_batcher_batch shall allocate enough memory for all the buffer handles in all the arrays + one extra header buffer handle. ]*/ - all_buffers = malloc(sizeof(CONSTBUFFER_HANDLE) * (total_buffer_count + 1)); + uint32_t all_buffers_array_size = total_buffer_count + 1; + all_buffers = malloc(sizeof(CONSTBUFFER_HANDLE) * ((size_t)all_buffers_array_size)); if (all_buffers == NULL) { /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_010: [ If any error occurrs, constbuffer_array_batcher_batch shall fail and return NULL. ]*/ @@ -109,8 +110,8 @@ CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDL } } - result = constbuffer_array_create(all_buffers, total_buffer_count + 1); - for (i = 0; i < current_index; i++) + result = constbuffer_array_create(all_buffers, all_buffers_array_size); + for (i = 0; i < all_buffers_array_size; i++) { CONSTBUFFER_DecRef(all_buffers[i]); } diff --git a/src/azure_c_shared_utility/crt_abstractions.c b/src/azure_c_shared_utility/crt_abstractions.c index 9e1f3e4..bf810d2 100644 --- a/src/azure_c_shared_utility/crt_abstractions.c +++ b/src/azure_c_shared_utility/crt_abstractions.c @@ -597,7 +597,7 @@ float strtof_s(const char* nptr, char** endptr) break; case FST_NUMBER: val = fraction * pow(10.0, (double)exponential) * (double)signal; - if ((val >= (FLT_MAX * (-1.0f))) && (val <= FLT_MAX)) + if ((val >= ((double)FLT_MAX * (-1.0))) && (val <= (double)FLT_MAX)) { /*Codes_SRS_CRT_ABSTRACTIONS_21_016: [The strtof_s must return the float that represents the value in the initial part of the string. If any.]*/ result = (float)val; diff --git a/src/azure_c_shared_utility/httpapiexsas.c b/src/azure_c_shared_utility/httpapiexsas.c index e221c1b..2886ac9 100644 --- a/src/azure_c_shared_utility/httpapiexsas.c +++ b/src/azure_c_shared_utility/httpapiexsas.c @@ -106,9 +106,9 @@ HTTPAPIEX_SAS_HANDLE HTTPAPIEX_SAS_Create(STRING_HANDLE key, STRING_HANDLE uriRe void HTTPAPIEX_SAS_Destroy(HTTPAPIEX_SAS_HANDLE handle) { /*Codes_SRS_HTTPAPIEXSAS_06_005: [If the parameter handle is NULL then HTTAPIEX_SAS_Destroy shall do nothing and return.]*/ - if (handle) + HTTPAPIEX_SAS_STATE* state = (HTTPAPIEX_SAS_STATE*)handle; + if (state) { - HTTPAPIEX_SAS_STATE* state = (HTTPAPIEX_SAS_STATE*)handle; /*Codes_SRS_HTTPAPIEXSAS_06_006: [HTTAPIEX_SAS_Destroy shall deallocate any structures denoted by the parameter handle.]*/ if (state->key) { diff --git a/src/azure_c_shared_utility/sastoken.c b/src/azure_c_shared_utility/sastoken.c index 5f9373b..d286fb6 100644 --- a/src/azure_c_shared_utility/sastoken.c +++ b/src/azure_c_shared_utility/sastoken.c @@ -23,7 +23,7 @@ static double getExpiryValue(const char* expiryASCII) { if (expiryASCII[i] >= '0' && expiryASCII[i] <= '9') { - value = value * 10 + (double)(expiryASCII[i] - '0'); + value = value * 10 + ((double)expiryASCII[i] - (double)'0'); } else { diff --git a/src/azure_c_shared_utility/sha384-512.c b/src/azure_c_shared_utility/sha384-512.c index ab097bd..84d1b1d 100644 --- a/src/azure_c_shared_utility/sha384-512.c +++ b/src/azure_c_shared_utility/sha384-512.c @@ -468,6 +468,9 @@ int SHA512Input(SHA512Context *context, uint64_t addTemp; if (!length) return shaSuccess; + + if (length > (sizeof(context->Message_Block) / sizeof(context->Message_Block[0]))) + return shaBadParam; if (!context || !message_array) return shaNull;