Commit d5c52464 authored by Kyle Nekritz's avatar Kyle Nekritz Committed by Facebook Github Bot

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
parent 8ecc23d9
......@@ -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) {
......
......@@ -1959,6 +1959,43 @@ TEST(AsyncSSLSocketTest, TestPreReceivedData) {
serverSock->getRawBytesReceived(), clientSock->getRawBytesWritten());
}
TEST(AsyncSSLSocketTest, TestMoveFromAsyncSocket) {
EventBase clientEventBase;
EventBase serverEventBase;
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
std::array<int, 2> 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<uint8_t, 10> 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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment