From a4220120ba7c565a8ad9311e80bdcbdd380c4705 Mon Sep 17 00:00:00 2001 From: toddouska Date: Wed, 31 Oct 2012 15:43:08 -0700 Subject: [PATCH] remove memset for setcokopt uninit --- src/io.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/io.c b/src/io.c index 2dba2a0dd..b9f2293b6 100644 --- a/src/io.c +++ b/src/io.c @@ -123,6 +123,16 @@ #endif +#ifdef CYASSL_DTLS + /* sizeof(struct timeval) will pass uninit bytes to setsockopt if padded */ + #ifdef USE_WINDOWS_API + #define TIMEVAL_BYTES sizeof(timeout) + #else + #define TIMEVAL_BYTES sizeof(timeout.tv_sec) + sizeof(timeout.tv_usec) + #endif +#endif + + static INLINE int LastError(void) { #ifdef USE_WINDOWS_API @@ -152,12 +162,10 @@ int EmbedReceive(CYASSL *ssl, char *buf, int sz, void *ctx) #ifdef USE_WINDOWS_API DWORD timeout = dtls_timeout * 1000; #else - struct timeval timeout; - XMEMSET(&timeout, 0, sizeof(struct timeval)); - timeout.tv_sec = dtls_timeout; + struct timeval timeout = {dtls_timeout, 0}; #endif setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, - (char*)&timeout, sizeof(timeout)); + (char*)&timeout, TIMEVAL_BYTES); } } #endif @@ -277,12 +285,10 @@ int EmbedReceiveFrom(CYASSL *ssl, char *buf, int sz, void *ctx) #ifdef USE_WINDOWS_API DWORD timeout = dtls_timeout * 1000; #else - struct timeval timeout; - XMEMSET(&timeout, 0, sizeof(struct timeval)); - timeout.tv_sec = dtls_timeout; + struct timeval timeout = { dtls_timeout, 0 }; #endif setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, - (char*)&timeout, sizeof(timeout)); + (char*)&timeout, TIMEVAL_BYTES); } recvd = (int)RECVFROM_FUNCTION(sd, buf, sz, ssl->rflags,