Prevent potential crash when a socket stream is closed while in a TLS handshake

This commit is contained in:
Wolfgang Lux 2019-10-28 16:47:44 +01:00
parent c4c8035ae5
commit e9427a9e20
2 changed files with 21 additions and 3 deletions

View file

@ -1,3 +1,9 @@
2019-10-28 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/GSSocketStream.m:
Prevent premature deallocation when a socket is closed while in a
TLS handshake.
2019-10-27 Fred Kiefer <fredkiefer@gmx.de>
* Headers/Foundation/NSUnit.h,

View file

@ -1584,14 +1584,26 @@ setNonBlocking(SOCKET fd)
*/
if (_handler != nil && [_handler handshake] == YES)
{
id hdl = _handler;
id del = _delegate;
BOOL val = _delegateValid;
_delegate = _handler;
/* Retain self to prevent a dangling pointer the handler closes and
* releases this socket. Also, do not restore the old delegate if it
* was changed directly or indirectly by the handler.
* FIXME We leave the socket an inconsistent state if any exception
* is raised in _sendEvent:.
*/
RETAIN(self);
_delegate = hdl;
_delegateValid = YES;
[super _sendEvent: event];
_delegate = del;
_delegateValid = val;
if (_delegate == hdl)
{
_delegate = del;
_delegateValid = val;
}
RELEASE(self);
}
else
{