From 79be0f22b131489173d6d6aa068f0f90f97e338b Mon Sep 17 00:00:00 2001 From: Billy Donahue Date: Thu, 19 Nov 2020 20:40:27 +0000 Subject: SERVER-51287 check socket() call for failure --- src/mongo/transport/transport_layer_asio.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mongo/transport/transport_layer_asio.cpp b/src/mongo/transport/transport_layer_asio.cpp index ea4c6c2dcf2..12f21911b56 100644 --- a/src/mongo/transport/transport_layer_asio.cpp +++ b/src/mongo/transport/transport_layer_asio.cpp @@ -50,6 +50,7 @@ #include "mongo/transport/asio_utils.h" #include "mongo/transport/service_entry_point.h" #include "mongo/transport/transport_options_gen.h" +#include "mongo/util/errno_util.h" #include "mongo/util/hierarchical_acquisition.h" #include "mongo/util/net/hostandport.h" #include "mongo/util/net/sockaddr.h" @@ -732,6 +733,11 @@ namespace { */ bool trySetSockOpt(int level, int opt, int val) { auto sock = ::socket(AF_INET, SOCK_STREAM, 0); + if (sock == -1) { + int ec = errno; + LOGV2_WARNING(5128700, "socket() failed", "error"_attr = errnoWithDescription(ec)); + return false; + } #ifdef _WIN32 char* pval = reinterpret_cast(&val); -- cgit v1.2.1