Skip to content

Commit

Permalink
fix(core): Fix issue on file descriptors where TLS packet is sent on …
Browse files Browse the repository at this point in the history
…invalid file descriptor when reusing fd
  • Loading branch information
WoodySlum committed Nov 14, 2023
1 parent 4cf26f5 commit 8ac29ca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions sope-appserver/NGObjWeb/WOWatchDogApplicationMain.m
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ - (void) receivedEvent: (void*)data
type: ET_RDESC
forMode: NSDefaultRunLoopMode
all: YES];
/* valid descriptor, but not alive .. so we close the socket */
[controlSocket shutdown];
[self setControlSocket: nil];
}
}
Expand Down
20 changes: 13 additions & 7 deletions sope-core/NGStreams/NGActiveSSLSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,16 @@ - (BOOL)shutdown {

if (self->session) {
int ret;
LOOP_CHECK(ret, gnutls_bye((gnutls_session_t)self->session, GNUTLS_SHUT_RDWR));
if (NGInvalidSocketDescriptor != self->fd) {
LOOP_CHECK(ret, gnutls_bye((gnutls_session_t)self->session, GNUTLS_SHUT_RDWR));
}
gnutls_deinit((gnutls_session_t) self->session);
self->session = NULL;
}
if (self->cred) {
gnutls_certificate_free_credentials((gnutls_certificate_credentials_t) self->cred);
if (NGInvalidSocketDescriptor != self->fd) {
gnutls_certificate_free_credentials((gnutls_certificate_credentials_t) self->cred);
}
self->cred = NULL;
}
return [super shutdown];
Expand Down Expand Up @@ -656,11 +660,13 @@ - (BOOL) startTLS

- (BOOL)shutdown {
if (self->ssl) {
int ret = SSL_shutdown(self->ssl);
// call shutdown a second time
if (ret == 0)
SSL_shutdown(self->ssl);
SSL_free(self->ssl);
if (NGInvalidSocketDescriptor != self->fd) {
int ret = SSL_shutdown(self->ssl);
// call shutdown a second time
if (ret == 0)
SSL_shutdown(self->ssl);
SSL_free(self->ssl);
}
self->ssl = NULL;
}
if (self->ctx) {
Expand Down
8 changes: 0 additions & 8 deletions sope-core/NGStreams/NGActiveSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,6 @@ - (BOOL)isAlive {
}

notAlive:
/* valid descriptor, but not alive .. so we close the socket */
#if defined(WIN32) && !defined(__CYGWIN32__)
closesocket(self->fd);
#else
close(self->fd);
#endif
self->fd = NGInvalidSocketDescriptor;
DESTROY(self->remoteAddress);
return NO;
}

Expand Down
2 changes: 2 additions & 0 deletions sope-mime/NGImap4/NGImap4Client.m
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ - (void)closeConnection {
self->text = nil;

NS_DURING
[self->socket shutdown];
[self->socket close];
[self->previous_socket shutdown];
[self->previous_socket close];
NS_HANDLER
[[self _handleSocketCloseException:localException] raise];
Expand Down

0 comments on commit 8ac29ca

Please sign in to comment.