Browse Source

avoid double delete

pull/99/head
orignal 10 years ago
parent
commit
b46b15cce4
  1. 16
      NTCPSession.cpp
  2. 4
      NTCPSession.h

16
NTCPSession.cpp

@ -255,6 +255,8 @@ namespace ntcp @@ -255,6 +255,8 @@ namespace ntcp
if (memcmp (hxy, m_Establisher->phase2.encrypted.hxy, 32))
{
LogPrint ("Incorrect hash");
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
m_DHKeysPair = nullptr;
Terminate ();
return ;
}
@ -427,7 +429,11 @@ namespace ntcp @@ -427,7 +429,11 @@ namespace ntcp
uint8_t * nextBlock = m_ReceiveBuffer;
while (m_ReceiveBufferOffset >= 16)
{
DecryptNextBlock (nextBlock); // 16 bytes
if (!DecryptNextBlock (nextBlock)) // 16 bytes
{
Terminate ();
return;
}
nextBlock += 16;
m_ReceiveBufferOffset -= 16;
}
@ -440,7 +446,7 @@ namespace ntcp @@ -440,7 +446,7 @@ namespace ntcp
}
}
void NTCPSession::DecryptNextBlock (const uint8_t * encrypted) // 16 bytes
bool NTCPSession::DecryptNextBlock (const uint8_t * encrypted) // 16 bytes
{
if (!m_NextMessage) // new message, header expected
{
@ -457,8 +463,7 @@ namespace ntcp @@ -457,8 +463,7 @@ namespace ntcp
LogPrint ("NTCP data size ", dataSize, " exceeds max size");
i2p::DeleteI2NPMessage (m_NextMessage);
m_NextMessage = nullptr;
Terminate ();
return;
return false;
}
m_NextMessageOffset += 16;
m_NextMessage->offset = 2; // size field
@ -470,7 +475,7 @@ namespace ntcp @@ -470,7 +475,7 @@ namespace ntcp
LogPrint ("Timestamp");
i2p::DeleteI2NPMessage (m_NextMessage);
m_NextMessage = nullptr;
return;
return true;
}
}
else // message continues
@ -485,6 +490,7 @@ namespace ntcp @@ -485,6 +490,7 @@ namespace ntcp
i2p::HandleI2NPMessage (m_NextMessage);
m_NextMessage = nullptr;
}
return true;
}
void NTCPSession::Send (i2p::I2NPMessage * msg)

4
NTCPSession.h

@ -112,7 +112,7 @@ namespace ntcp @@ -112,7 +112,7 @@ namespace ntcp
// common
void Receive ();
void HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void DecryptNextBlock (const uint8_t * encrypted);
bool DecryptNextBlock (const uint8_t * encrypted);
void Send (i2p::I2NPMessage * msg);
void HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, i2p::I2NPMessage * msg);
@ -143,7 +143,7 @@ namespace ntcp @@ -143,7 +143,7 @@ namespace ntcp
NTCPPhase4 phase4;
} * m_Establisher;
uint8_t m_ReceiveBuffer[NTCP_BUFFER_SIZE], m_TimeSyncBuffer[16];
uint8_t m_ReceiveBuffer[NTCP_BUFFER_SIZE + 16], m_TimeSyncBuffer[16];
int m_ReceiveBufferOffset;
i2p::I2NPMessage * m_NextMessage;

Loading…
Cancel
Save