From d5c52464f21358b50304481d21fb6345ee3434f2 Mon Sep 17 00:00:00 2001 From: Kyle Nekritz Date: Fri, 10 Mar 2017 09:36:52 -0800 Subject: [PATCH] Fix use after move in AsyncSSLSocket constructor. Summary: The new AsyncSocket is already constructed at this point so just use the event base from it. Reviewed By: djwatson Differential Revision: D4689395 fbshipit-source-id: aac898c1c6e6e0e0ffcb20b16bbf2b842cc31d54 --- folly/io/async/AsyncSSLSocket.cpp | 4 +-- folly/io/async/test/AsyncSSLSocketTest.cpp | 37 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/folly/io/async/AsyncSSLSocket.cpp b/folly/io/async/AsyncSSLSocket.cpp index 26090b7b..3d16fc68 100644 --- a/folly/io/async/AsyncSSLSocket.cpp +++ b/folly/io/async/AsyncSSLSocket.cpp @@ -248,8 +248,8 @@ AsyncSSLSocket::AsyncSSLSocket( : AsyncSocket(std::move(oldAsyncSocket)), server_(server), ctx_(ctx), - handshakeTimeout_(this, oldAsyncSocket->getEventBase()), - connectionTimeout_(this, oldAsyncSocket->getEventBase()) { + handshakeTimeout_(this, AsyncSocket::getEventBase()), + connectionTimeout_(this, AsyncSocket::getEventBase()) { noTransparentTls_ = true; init(); if (server) { diff --git a/folly/io/async/test/AsyncSSLSocketTest.cpp b/folly/io/async/test/AsyncSSLSocketTest.cpp index fbbf999b..72359925 100644 --- a/folly/io/async/test/AsyncSSLSocketTest.cpp +++ b/folly/io/async/test/AsyncSSLSocketTest.cpp @@ -1959,6 +1959,43 @@ TEST(AsyncSSLSocketTest, TestPreReceivedData) { serverSock->getRawBytesReceived(), clientSock->getRawBytesWritten()); } +TEST(AsyncSSLSocketTest, TestMoveFromAsyncSocket) { + EventBase clientEventBase; + EventBase serverEventBase; + auto clientCtx = std::make_shared(); + auto dfServerCtx = std::make_shared(); + std::array fds; + getfds(fds.data()); + getctx(clientCtx, dfServerCtx); + + AsyncSSLSocket::UniquePtr clientSockPtr( + new AsyncSSLSocket(clientCtx, &clientEventBase, fds[0], false)); + AsyncSocket::UniquePtr serverSockPtr( + new AsyncSocket(&serverEventBase, fds[1])); + auto clientSock = clientSockPtr.get(); + auto serverSock = serverSockPtr.get(); + SSLHandshakeClient client(std::move(clientSockPtr), true, true); + + // Steal some data from the server. + clientEventBase.loopOnce(); + std::array buf; + recv(fds[1], buf.data(), buf.size(), 0); + serverSock->setPreReceivedData(IOBuf::wrapBuffer(range(buf))); + AsyncSSLSocket::UniquePtr serverSSLSockPtr( + new AsyncSSLSocket(dfServerCtx, std::move(serverSockPtr), true)); + auto serverSSLSock = serverSSLSockPtr.get(); + SSLHandshakeServer server(std::move(serverSSLSockPtr), true, true); + while (!client.handshakeSuccess_ && !client.handshakeError_) { + serverEventBase.loopOnce(); + clientEventBase.loopOnce(); + } + + EXPECT_TRUE(client.handshakeSuccess_); + EXPECT_TRUE(server.handshakeSuccess_); + EXPECT_EQ( + serverSSLSock->getRawBytesReceived(), clientSock->getRawBytesWritten()); +} + /** * Test overriding the flags passed to "sendmsg()" system call, * and verifying that write requests fail properly. -- 2.34.1