Skip to content

Commit

Permalink
Bug 1614870 - Free sid->peerID before reallocating in ssl_DecodeResum…
Browse files Browse the repository at this point in the history
…ptionToken. r=mt

This patch adds a missing `PORT_Free()` when reallocating `sid->PeerID`, and adds a test for a non-empty PeerID.

Differential Revision: https://phabricator.services.mozilla.com/D62653

--HG--
extra : moz-landing-system : lando
  • Loading branch information
Kevin Jacobs committed Feb 12, 2020
1 parent df7777a commit 0c8ff00
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
35 changes: 33 additions & 2 deletions gtests/ssl_gtest/ssl_resumption_unittest.cc
Expand Up @@ -838,7 +838,7 @@ TEST_F(TlsConnectTest, TestTls13ResumptionDuplicateNST) {

// Clear the session ticket keys to invalidate the old ticket.
SSLInt_ClearSelfEncryptKey();
SSL_SendSessionTicket(server_->ssl_fd(), NULL, 0);
EXPECT_EQ(SECSuccess, SSL_SendSessionTicket(server_->ssl_fd(), NULL, 0));

SendReceive(); // Need to read so that we absorb the session tickets.
CheckKeys();
Expand Down Expand Up @@ -1005,7 +1005,8 @@ TEST_F(TlsConnectStreamTls13, ExternalResumptionUseSecondTicket) {
state->invoked++;
return SECSuccess;
};
SSL_SetResumptionTokenCallback(client_->ssl_fd(), cb, &ticket_state);
EXPECT_EQ(SECSuccess, SSL_SetResumptionTokenCallback(client_->ssl_fd(), cb,
&ticket_state));

Connect();
EXPECT_EQ(SECSuccess, SSL_SendSessionTicket(server_->ssl_fd(), nullptr, 0));
Expand Down Expand Up @@ -1446,4 +1447,34 @@ TEST_F(TlsConnectStreamTls13, ExternalTokenAfterHrr) {
SendReceive();
}

TEST_F(TlsConnectStreamTls13, ExternalTokenWithPeerId) {
ConfigureSessionCache(RESUME_BOTH, RESUME_BOTH);
ConfigureVersion(SSL_LIBRARY_VERSION_TLS_1_3);
EXPECT_EQ(SECSuccess, SSL_SetSockPeerID(client_->ssl_fd(), "testPeerId"));
std::vector<uint8_t> ticket_state;
auto cb = [](PRFileDesc* fd, const PRUint8* ticket, unsigned int ticket_len,
void* arg) -> SECStatus {
EXPECT_NE(0U, ticket_len);
EXPECT_NE(nullptr, ticket);
auto ticket_state_ = reinterpret_cast<std::vector<uint8_t>*>(arg);
ticket_state_->assign(ticket, ticket + ticket_len);
return SECSuccess;
};
EXPECT_EQ(SECSuccess, SSL_SetResumptionTokenCallback(client_->ssl_fd(), cb,
&ticket_state));

Connect();
SendReceive();
EXPECT_NE(0U, ticket_state.size());

Reset();
ConfigureSessionCache(RESUME_BOTH, RESUME_BOTH);
EXPECT_EQ(SECSuccess, SSL_SetSockPeerID(client_->ssl_fd(), "testPeerId"));
client_->SetResumptionToken(ticket_state);
ASSERT_TRUE(client_->MaybeSetResumptionToken());
ExpectResumption(RESUME_TICKET);
Connect();
SendReceive();
}

} // namespace nss_test
3 changes: 3 additions & 0 deletions lib/ssl/sslnonce.c
Expand Up @@ -537,6 +537,9 @@ ssl_DecodeResumptionToken(sslSessionID *sid, const PRUint8 *encodedToken,
}
if (readerBuffer.len) {
PORT_Assert(readerBuffer.buf);
if (sid->peerID) {
PORT_Free((void *)sid->peerID);
}
sid->peerID = PORT_Strdup((const char *)readerBuffer.buf);
}

Expand Down

0 comments on commit 0c8ff00

Please sign in to comment.