1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

sktree is indexed on the numeric value of the socket structure's

underlying WinSock SOCKET. Therefore, if we plan to modify the
SOCKET in a socket, we must remove it from the tree before doing so,
and put it back again afterwards. Otherwise it'll violate the tree's
sorting order, and sooner or later someone will try to find it and
get back NULL.

[originally from svn r7795]
This commit is contained in:
Simon Tatham 2007-11-26 21:09:54 +00:00
parent 868208b8bd
commit 712b4689c8

View File

@ -96,6 +96,10 @@ static int cmpfortree(void *av, void *bv)
return -1; return -1;
if (as > bs) if (as > bs)
return +1; return +1;
if (a < b)
return -1;
if (a > b)
return +1;
return 0; return 0;
} }
@ -788,6 +792,14 @@ static DWORD try_connect(Actual_Socket sock)
family = AF_INET; family = AF_INET;
} }
/*
* Remove the socket from the tree before we overwrite its
* internal socket id, because that forms part of the tree's
* sorting criterion. We'll add it back before exiting this
* function, whether we changed anything or not.
*/
del234(sktree, sock);
s = p_socket(family, SOCK_STREAM, 0); s = p_socket(family, SOCK_STREAM, 0);
sock->s = s; sock->s = s;
@ -932,11 +944,15 @@ static DWORD try_connect(Actual_Socket sock)
sock->writable = 1; sock->writable = 1;
} }
add234(sktree, sock);
err = 0; err = 0;
ret: ret:
/*
* No matter what happened, put the socket back in the tree.
*/
add234(sktree, sock);
if (err) if (err)
plug_log(sock->plug, 1, sock->addr, sock->port, sock->error, err); plug_log(sock->plug, 1, sock->addr, sock->port, sock->error, err);
return err; return err;