From: Kyle Nekritz Date: Fri, 10 Mar 2017 17:36:52 +0000 (-0800) Subject: Fix use after move in AsyncSSLSocket constructor. X-Git-Tag: v2017.03.13.00~4 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d5c52464f21358b50304481d21fb6345ee3434f2;p=folly.git 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 --- 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.