Skip to content

Commit de3d161

Browse files
BUG#17259750 - STACK CORRUPTION IN VIO_IO_WAIT ON MAC OS X
Description & Fix: On OS X, vio_io_wait is implemented using select system call (as per analysis in bug#11748945). The select system call cannot handle file descriptors greater than or equal to FD_SETSIZE. This causes stack corruption when FD_SET is used on this range of file descriptors. This fix is check if fd exceeds or equals FD_SETSIZE in vio_io_wait and return failure. Also if the connected file descriptor exceeds or equal FD_SETSIZE, do not accept the connection on OS X.
1 parent 9b70ec0 commit de3d161

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sql/conn_handler/socket_connection.cc

+11
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,17 @@ Channel_info* Mysqld_socket_listener::listen_for_connection_event()
921921
return NULL;
922922
}
923923

924+
#ifdef __APPLE__
925+
if (mysql_socket_getfd(connect_sock) >= FD_SETSIZE)
926+
{
927+
sql_print_warning("File Descriptor %d exceedeed FD_SETSIZE=%d",
928+
mysql_socket_getfd(connect_sock), FD_SETSIZE);
929+
connection_errors_internal++;
930+
(void) mysql_socket_close(connect_sock);
931+
return NULL;
932+
}
933+
#endif
934+
924935
#ifdef HAVE_LIBWRAP
925936
if (!is_unix_socket)
926937
{

vio/viosocket.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or
55
modify it under the terms of the GNU General Public License
@@ -821,6 +821,11 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout)
821821
if (fd == INVALID_SOCKET)
822822
DBUG_RETURN(-1);
823823

824+
#ifdef __APPLE__
825+
if (fd >= FD_SETSIZE)
826+
DBUG_RETURN(-1);
827+
#endif
828+
824829
/* Convert the timeout, in milliseconds, to seconds and microseconds. */
825830
if (timeout >= 0)
826831
{

0 commit comments

Comments
 (0)