Browse Source

avoid double delete

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

18
NTCPSession.cpp

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

4
NTCPSession.h

@ -112,7 +112,7 @@ namespace ntcp
// common // common
void Receive (); void Receive ();
void HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred); 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 Send (i2p::I2NPMessage * msg);
void HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, 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
NTCPPhase4 phase4; NTCPPhase4 phase4;
} * m_Establisher; } * 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; int m_ReceiveBufferOffset;
i2p::I2NPMessage * m_NextMessage; i2p::I2NPMessage * m_NextMessage;

Loading…
Cancel
Save