Skip to content

Commit 0047309

Browse files
adamtronMongoDB Bot
authored andcommitted
SERVER-98593 Add a fallback error code for when we get SSL_ERROR_SYSCALL without an associated error (#30759)
GitOrigin-RevId: 59fa9c2b8778e7fdf14f204701432413128e67dc
1 parent 8535211 commit 0047309

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/mongo/util/net/ssl/detail/impl/engine_openssl.ipp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// ssl/detail/impl/engine.ipp
33
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
44
//
5-
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
5+
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
66
//
77
// Distributed under the Boost Software License, Version 1.0. (See accompanying
88
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -190,12 +190,16 @@ engine::want engine::perform(int (engine::*op)(void*, std::size_t),
190190

191191
if (ssl_error == SSL_ERROR_SSL) {
192192
ec = asio::error_code(sys_error, asio::error::get_ssl_category());
193-
return want_nothing;
193+
return pending_output_after > pending_output_before ? want_output : want_nothing;
194194
}
195195

196196
if (ssl_error == SSL_ERROR_SYSCALL) {
197-
ec = asio::error_code(sys_error, asio::error::get_system_category());
198-
return want_nothing;
197+
if (sys_error == 0) {
198+
ec = asio::ssl::error::unspecified_system_error;
199+
} else {
200+
ec = asio::error_code(sys_error, asio::error::get_ssl_category());
201+
}
202+
return pending_output_after > pending_output_before ? want_output : want_nothing;
199203
}
200204

201205
if (result > 0 && bytes_transferred)
@@ -210,12 +214,15 @@ engine::want engine::perform(int (engine::*op)(void*, std::size_t),
210214
} else if (ssl_error == SSL_ERROR_WANT_READ) {
211215
ec = asio::error_code();
212216
return want_input_and_retry;
213-
} else if (::SSL_get_shutdown(ssl_) & SSL_RECEIVED_SHUTDOWN) {
217+
} else if (ssl_error == SSL_ERROR_ZERO_RETURN) {
214218
ec = asio::error::eof;
215219
return want_nothing;
216-
} else {
220+
} else if (ssl_error == SSL_ERROR_NONE) {
217221
ec = asio::error_code();
218222
return want_nothing;
223+
} else {
224+
ec = asio::ssl::error::unexpected_result;
225+
return want_nothing;
219226
}
220227
}
221228

src/mongo/util/net/ssl/error.hpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,27 @@ namespace error {
4343
enum stream_errors {
4444
#if defined(GENERATING_DOCUMENTATION)
4545
/// The underlying stream closed before the ssl stream gracefully shut down.
46-
stream_truncated,
47-
no_renegotiation
48-
#elif (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL) && \
46+
stream_truncated = 0,
47+
48+
/// The underlying SSL library returned a system error without providing
49+
/// further information.
50+
unspecified_system_error = 1,
51+
52+
/// The underlying SSL library generated an unexpected result from a function
53+
/// call.
54+
unexpected_result = 2,
55+
no_renegotiation = 8,
56+
#else // defined(GENERATING_DOCUMENTATION)
57+
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL) && \
4958
MONGO_CONFIG_SSL_PROVIDER == MONGO_CONFIG_SSL_PROVIDER_OPENSSL
50-
stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)
59+
stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ),
5160
#else
5261
stream_truncated = 1,
53-
no_renegotiation
62+
no_renegotiation = 8,
5463
#endif
64+
unspecified_system_error = 2,
65+
unexpected_result = 3
66+
#endif // defined(GENERATING_DOCUMENTATION)
5567
};
5668

5769
extern ASIO_DECL const asio::error_category& get_stream_category();

src/mongo/util/net/ssl/impl/error.ipp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public:
9191
switch (value) {
9292
case stream_truncated:
9393
return "stream truncated";
94+
case unspecified_system_error:
95+
return "unspecified system error";
96+
case unexpected_result:
97+
return "unexpected result";
9498
default:
9599
return "asio.ssl.stream error";
96100
}

0 commit comments

Comments
 (0)