Mercurial > dropbear
changeset 1596:60fceff95858
workaround memory sanitizer FD_ZERO false positives
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 06 Mar 2018 21:51:51 +0800 |
parents | 4fe7cc9e45eb |
children | 8f7b6f75aa58 |
files | common-session.c dbrandom.c dbutil.h fuzz-wrapfd.c svr-main.c sysoptions.h |
diffstat | 6 files changed, 30 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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 */
--- 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)
--- 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_ */
--- 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) {
--- 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++) {
--- 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 */