dtls defaults to no static buffers now, fix valgrind errors with dtls

This commit is contained in:
toddouska
2013-03-15 14:21:36 -07:00
parent ae63878700
commit 31b03c8a2d
3 changed files with 21 additions and 6 deletions

View File

@ -828,7 +828,7 @@ enum {
The length (in bytes) of the following TLSPlaintext.fragment. The length (in bytes) of the following TLSPlaintext.fragment.
The length should not exceed 2^14. 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 + \ #define STATIC_BUFFER_LEN RECORD_HEADER_SZ + RECORD_SIZE + COMP_EXTRA + \
MTU_EXTRA + MAX_MSG_EXTRA MTU_EXTRA + MAX_MSG_EXTRA
#else #else

View File

@ -4167,6 +4167,7 @@ static int GetInputData(CYASSL *ssl, word32 size)
int inSz; int inSz;
int maxLength; int maxLength;
int usedLength; int usedLength;
int dtlsExtra = 0;
/* check max input length */ /* check max input length */
@ -4175,12 +4176,15 @@ static int GetInputData(CYASSL *ssl, word32 size)
inSz = (int)(size - usedLength); /* from last partial read */ inSz = (int)(size - usedLength); /* from last partial read */
#ifdef CYASSL_DTLS #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 */ inSz = MAX_MTU; /* read ahead up to MTU */
}
#endif #endif
if (inSz > maxLength) { if (inSz > maxLength) {
if (GrowInputBuffer(ssl, size, usedLength) < 0) if (GrowInputBuffer(ssl, size + dtlsExtra, usedLength) < 0)
return MEMORY_E; return MEMORY_E;
} }
@ -5188,6 +5192,7 @@ int SendAlert(CYASSL* ssl, int severity, int type)
byte *output; byte *output;
int sendSz; int sendSz;
int ret; int ret;
int dtlsExtra = 0;
/* if sendalert is called again for nonbloking */ /* if sendalert is called again for nonbloking */
if (ssl->options.sendAlertState != 0) { if (ssl->options.sendAlertState != 0) {
@ -5197,8 +5202,14 @@ int SendAlert(CYASSL* ssl, int severity, int type)
return ret; return ret;
} }
#ifdef CYASSL_DTLS
if (ssl->options.dtls)
dtlsExtra = DTLS_RECORD_EXTRA;
#endif
/* check for avalaible size */ /* 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; return ret;
/* get ouput buffer */ /* get ouput buffer */

View File

@ -192,7 +192,9 @@ int EmbedReceive(CYASSL *ssl, char *buf, int sz, void *ctx)
#ifdef USE_WINDOWS_API #ifdef USE_WINDOWS_API
DWORD timeout = dtls_timeout * 1000; DWORD timeout = dtls_timeout * 1000;
#else #else
struct timeval timeout = {dtls_timeout, 0}; struct timeval timeout;
XMEMSET(&timeout, 0, sizeof(timeout));
timeout.tv_sec = dtls_timeout;
#endif #endif
if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout,
sizeof(timeout)) != 0) { sizeof(timeout)) != 0) {
@ -324,7 +326,9 @@ int EmbedReceiveFrom(CYASSL *ssl, char *buf, int sz, void *ctx)
#ifdef USE_WINDOWS_API #ifdef USE_WINDOWS_API
DWORD timeout = dtls_timeout * 1000; DWORD timeout = dtls_timeout * 1000;
#else #else
struct timeval timeout = { dtls_timeout, 0 }; struct timeval timeout;
XMEMSET(&timeout, 0, sizeof(timeout));
timeout.tv_sec = dtls_timeout;
#endif #endif
if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout,
sizeof(timeout)) != 0) { sizeof(timeout)) != 0) {