Skip to content

Commit 45b68aa

Browse files
committed
Fix stack overflow when debug enabled in MbedTLS wrapper
Fixes aws#63
1 parent c8b39c9 commit 45b68aa

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

platform/linux/mbedtls/network_mbedtls_wrapper.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@ extern "C" {
2727
#include "network_interface.h"
2828
#include "network_platform.h"
2929

30+
3031
/* This is the value used for ssl read timeout */
3132
#define IOT_SSL_READ_TIMEOUT 10
3233

34+
/* This defines the value of the debug buffer that gets allocated.
35+
* The value can be altered based on memory constraints
36+
*/
37+
#ifdef ENABLE_IOT_DEBUG
38+
#define MBEDTLS_DEBUG_BUFFER_SIZE 2048
39+
#endif
40+
3341
/*
3442
* This is a function to do further verification if needed on the cert received
3543
*/
@@ -93,8 +101,9 @@ IoT_Error_t iot_tls_connect(Network *pNetwork, TLSConnectParams *params) {
93101
TLSDataParams *tlsDataParams = NULL;
94102
char portBuffer[6];
95103
char vrfy_buf[512];
96-
#ifdef IOT_DEBUG
97-
unsigned char buf[MBEDTLS_SSL_MAX_CONTENT_LEN + 1];
104+
105+
#ifdef ENABLE_IOT_DEBUG
106+
unsigned char buf[MBEDTLS_DEBUG_BUFFER_SIZE];
98107
#endif
99108

100109
if(NULL == pNetwork) {
@@ -248,7 +257,7 @@ IoT_Error_t iot_tls_connect(Network *pNetwork, TLSConnectParams *params) {
248257
ret = SUCCESS;
249258
}
250259

251-
#ifdef IOT_DEBUG
260+
#ifdef ENABLE_IOT_DEBUG
252261
if (mbedtls_ssl_get_peer_cert(&(tlsDataParams->ssl)) != NULL) {
253262
IOT_DEBUG(" . Peer certificate information ...\n");
254263
mbedtls_x509_crt_info((char *) buf, sizeof(buf) - 1, " ", mbedtls_ssl_get_peer_cert(&(tlsDataParams->ssl)));

0 commit comments

Comments
 (0)