# HG changeset patch # User Matt Johnston # Date 1520344311 -28800 # Node ID 60fceff958581d84453883057f74e1bfd23b28f4 # Parent 4fe7cc9e45eb4f27bc29313f1c4e742cc99ec6c3 workaround memory sanitizer FD_ZERO false positives diff -r 4fe7cc9e45eb -r 60fceff95858 common-session.c --- a/common-session.c Tue Mar 06 21:00:09 2018 +0800 +++ b/common-session.c Tue Mar 06 21:51:51 2018 +0800 @@ -152,8 +152,9 @@ timeout.tv_sec = select_timeout(); timeout.tv_usec = 0; - FD_ZERO(&writefd); - FD_ZERO(&readfd); + DROPBEAR_FD_ZERO(&writefd); + DROPBEAR_FD_ZERO(&readfd); + dropbear_assert(ses.payload == NULL); /* We get woken up when signal handlers write to this pipe. @@ -204,8 +205,8 @@ * want to iterate over channels etc for reading, to handle * server processes exiting etc. * We don't want to read/write FDs. */ - FD_ZERO(&writefd); - FD_ZERO(&readfd); + DROPBEAR_FD_ZERO(&writefd); + DROPBEAR_FD_ZERO(&readfd); } /* We'll just empty out the pipe if required. We don't do @@ -406,7 +407,7 @@ return -1; } - FD_ZERO(&fds); + DROPBEAR_FD_ZERO(&fds); /* select since it's a non-blocking fd */ diff -r 4fe7cc9e45eb -r 60fceff95858 dbrandom.c --- a/dbrandom.c Tue Mar 06 21:00:09 2018 +0800 +++ b/dbrandom.c Tue Mar 06 21:51:51 2018 +0800 @@ -88,7 +88,7 @@ timeout.tv_sec = 2; timeout.tv_usec = 0; - FD_ZERO(&read_fds); + DROPBEAR_FD_ZERO(&read_fds); FD_SET(readfd, &read_fds); res = select(readfd + 1, &read_fds, NULL, NULL, &timeout); if (res == 0) diff -r 4fe7cc9e45eb -r 60fceff95858 dbutil.h --- a/dbutil.h Tue Mar 06 21:00:09 2018 +0800 +++ b/dbutil.h Tue Mar 06 21:51:51 2018 +0800 @@ -88,4 +88,11 @@ void fsync_parent_dir(const char* fn); +#if DROPBEAR_MSAN +/* FD_ZERO seems to leave some memory uninitialized. clear it to avoid false positives */ +#define DROPBEAR_FD_ZERO(fds) do { memset((fds), 0x0, sizeof(fd_set)); FD_ZERO(fds); } while(0) +#else +#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds) +#endif + #endif /* DROPBEAR_DBUTIL_H_ */ diff -r 4fe7cc9e45eb -r 60fceff95858 fuzz-wrapfd.c --- a/fuzz-wrapfd.c Tue Mar 06 21:00:09 2018 +0800 +++ b/fuzz-wrapfd.c Tue Mar 06 21:51:51 2018 +0800 @@ -2,6 +2,8 @@ #include "includes.h" #include "fuzz-wrapfd.h" +#include "dbutil.h" + #include "fuzz.h" #define IOWRAP_MAXFD (FD_SETSIZE-1) @@ -195,7 +197,7 @@ nset++; } } - FD_ZERO(readfds); + DROPBEAR_FD_ZERO(readfds); if (nset > 0) { /* set one */ @@ -222,7 +224,7 @@ nset++; } } - FD_ZERO(writefds); + DROPBEAR_FD_ZERO(writefds); /* set one */ if (nset > 0) { diff -r 4fe7cc9e45eb -r 60fceff95858 svr-main.c --- a/svr-main.c Tue Mar 06 21:00:09 2018 +0800 +++ b/svr-main.c Tue Mar 06 21:51:51 2018 +0800 @@ -178,7 +178,7 @@ /* incoming connection select loop */ for(;;) { - FD_ZERO(&fds); + DROPBEAR_FD_ZERO(&fds); /* listening sockets */ for (i = 0; i < listensockcount; i++) { diff -r 4fe7cc9e45eb -r 60fceff95858 sysoptions.h --- a/sysoptions.h Tue Mar 06 21:00:09 2018 +0800 +++ b/sysoptions.h Tue Mar 06 21:51:51 2018 +0800 @@ -318,4 +318,15 @@ #define DROPBEAR_TRACKING_MALLOC (DROPBEAR_FUZZ) +/* Used to work around Memory Sanitizer false positives */ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) +# define DROPBEAR_MSAN 1 +# endif +#endif +#ifndef DROPBEAR_MSAN +#define DROPBEAR_MSAN 0 +#endif + + /* no include guard for this file */