From 9be42299b58a443e3612dbea262448fff029853d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 29 Oct 2011 17:16:08 +0200 Subject: [PATCH] Guard against unusable fd in pthreads' empth_select() 0 <= fd < FD_SETSIZE must hold, or else undefined behavior in FD_SET(). --- src/lib/empthread/pthread.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/empthread/pthread.c b/src/lib/empthread/pthread.c index 6339459e3..0c0ef5dcd 100644 --- a/src/lib/empthread/pthread.c +++ b/src/lib/empthread/pthread.c @@ -29,7 +29,7 @@ * Known contributors to this file: * Sasha Mikheev * Steve McClure, 1998 - * Markus Armbruster, 2005-2010 + * Markus Armbruster, 2005-2011 * Ron Koenderink, 2007-2009 */ @@ -289,6 +289,11 @@ empth_select(int fd, int flags, struct timeval *timeout) empth_t *ctx; int res = 0; + if (CANT_HAPPEN(fd < 0 || fd >= FD_SETSIZE)) { + errno = EBADF; + return -1; + } + ef_make_stale(); pthread_mutex_unlock(&mtx_ctxsw); empth_status("select on %d for %d", fd, flags); -- 2.43.0