work around "unexpected EOF" error messages at end of SSL connections

gmail apparently doesn't send a close notification (SSL_shutdown())
before closing the TCP socket.
This commit is contained in:
Oswald Buddenhagen 2022-06-06 11:55:37 +02:00
parent 6b22c837f6
commit b6c36624f0
3 changed files with 15 additions and 2 deletions

View File

@ -1620,6 +1620,7 @@ imap_socket_read( void *aux )
error( "IMAP error: unexpected BYE response: %s\n", cmd ); error( "IMAP error: unexpected BYE response: %s\n", cmd );
/* We just wait for the server to close the connection now. */ /* We just wait for the server to close the connection now. */
ctx->expectEOF = 1; ctx->expectEOF = 1;
socket_expect_eof( &ctx->conn );
} else { } else {
/* We still need to wait for the LOGOUT's tagged OK. */ /* We still need to wait for the LOGOUT's tagged OK. */
} }
@ -1882,10 +1883,12 @@ static void
imap_cleanup_p2( imap_store_t *ctx, imap_cleanup_p2( imap_store_t *ctx,
imap_cmd_t *cmd ATTR_UNUSED, int response ) imap_cmd_t *cmd ATTR_UNUSED, int response )
{ {
if (response == RESP_NO) if (response == RESP_NO) {
imap_cancel_store( &ctx->gen ); imap_cancel_store( &ctx->gen );
else if (response == RESP_OK) } else if (response == RESP_OK) {
ctx->expectEOF = 1; ctx->expectEOF = 1;
socket_expect_eof( &ctx->conn );
}
} }
/******************* imap_open_store *******************/ /******************* imap_open_store *******************/

View File

@ -810,6 +810,15 @@ socket_expect_activity( conn_t *conn, int expect )
conf_wakeup( &conn->fd_timeout, expect ? conn->conf->timeout : -1 ); conf_wakeup( &conn->fd_timeout, expect ? conn->conf->timeout : -1 );
} }
void
socket_expect_eof( conn_t *sock )
{
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF // implies HAVE_LIBSSL
if (sock->ssl)
SSL_set_options( sock->ssl, SSL_OP_IGNORE_UNEXPECTED_EOF );
#endif
}
int int
socket_read( conn_t *conn, char *buf, uint len ) socket_read( conn_t *conn, char *buf, uint len )
{ {

View File

@ -142,6 +142,7 @@ void socket_start_tls(conn_t *conn, void (*cb)( int ok, void *aux ) );
void socket_start_deflate( conn_t *conn ); void socket_start_deflate( conn_t *conn );
void socket_close( conn_t *sock ); void socket_close( conn_t *sock );
void socket_expect_activity( conn_t *sock, int expect ); void socket_expect_activity( conn_t *sock, int expect );
void socket_expect_eof( conn_t *sock );
int socket_read( conn_t *sock, char *buf, uint len ); /* never waits */ int socket_read( conn_t *sock, char *buf, uint len ); /* never waits */
char *socket_read_line( conn_t *sock ); /* don't free return value; never waits */ char *socket_read_line( conn_t *sock ); /* don't free return value; never waits */
typedef enum { KeepOwn = 0, GiveOwn } ownership_t; typedef enum { KeepOwn = 0, GiveOwn } ownership_t;