From 31b03c8a2df1cfb1a7a2db3cf288b527fafdd035 Mon Sep 17 00:00:00 2001 From: toddouska Date: Fri, 15 Mar 2013 14:21:36 -0700 Subject: [PATCH] dtls defaults to no static buffers now, fix valgrind errors with dtls --- cyassl/internal.h | 2 +- src/internal.c | 17 ++++++++++++++--- src/io.c | 8 ++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cyassl/internal.h b/cyassl/internal.h index e7ca9dddc..1ece4556f 100644 --- a/cyassl/internal.h +++ b/cyassl/internal.h @@ -828,7 +828,7 @@ enum { The length (in bytes) of the following TLSPlaintext.fragment. The length should not exceed 2^14. */ -#if defined(LARGE_STATIC_BUFFERS) || defined(CYASSL_DTLS) +#if defined(LARGE_STATIC_BUFFERS) #define STATIC_BUFFER_LEN RECORD_HEADER_SZ + RECORD_SIZE + COMP_EXTRA + \ MTU_EXTRA + MAX_MSG_EXTRA #else diff --git a/src/internal.c b/src/internal.c index 1bdbda1e3..bb3825acd 100644 --- a/src/internal.c +++ b/src/internal.c @@ -4167,6 +4167,7 @@ static int GetInputData(CYASSL *ssl, word32 size) int inSz; int maxLength; int usedLength; + int dtlsExtra = 0; /* check max input length */ @@ -4175,12 +4176,15 @@ static int GetInputData(CYASSL *ssl, word32 size) inSz = (int)(size - usedLength); /* from last partial read */ #ifdef CYASSL_DTLS - if (ssl->options.dtls) + if (ssl->options.dtls) { + if (size < MAX_MTU) + dtlsExtra = (int)(MAX_MTU - size); inSz = MAX_MTU; /* read ahead up to MTU */ + } #endif if (inSz > maxLength) { - if (GrowInputBuffer(ssl, size, usedLength) < 0) + if (GrowInputBuffer(ssl, size + dtlsExtra, usedLength) < 0) return MEMORY_E; } @@ -5188,6 +5192,7 @@ int SendAlert(CYASSL* ssl, int severity, int type) byte *output; int sendSz; int ret; + int dtlsExtra = 0; /* if sendalert is called again for nonbloking */ if (ssl->options.sendAlertState != 0) { @@ -5197,8 +5202,14 @@ int SendAlert(CYASSL* ssl, int severity, int type) return ret; } + #ifdef CYASSL_DTLS + if (ssl->options.dtls) + dtlsExtra = DTLS_RECORD_EXTRA; + #endif + /* check for avalaible size */ - if ((ret = CheckAvalaibleSize(ssl, ALERT_SIZE + MAX_MSG_EXTRA)) != 0) + if ((ret = CheckAvalaibleSize(ssl, + ALERT_SIZE + MAX_MSG_EXTRA + dtlsExtra)) != 0) return ret; /* get ouput buffer */ diff --git a/src/io.c b/src/io.c index 9e4a763c9..7fe4f0260 100644 --- a/src/io.c +++ b/src/io.c @@ -192,7 +192,9 @@ int EmbedReceive(CYASSL *ssl, char *buf, int sz, void *ctx) #ifdef USE_WINDOWS_API DWORD timeout = dtls_timeout * 1000; #else - struct timeval timeout = {dtls_timeout, 0}; + struct timeval timeout; + XMEMSET(&timeout, 0, sizeof(timeout)); + timeout.tv_sec = dtls_timeout; #endif if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) != 0) { @@ -324,7 +326,9 @@ int EmbedReceiveFrom(CYASSL *ssl, char *buf, int sz, void *ctx) #ifdef USE_WINDOWS_API DWORD timeout = dtls_timeout * 1000; #else - struct timeval timeout = { dtls_timeout, 0 }; + struct timeval timeout; + XMEMSET(&timeout, 0, sizeof(timeout)); + timeout.tv_sec = dtls_timeout; #endif if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) != 0) {