(trunk, libT) #5451: 'crash in tr_torrentGetPeerId() during incoming encrypted handshake' -- fixed.
This commit is contained in:
parent
229f9e5ae6
commit
76528d8e14
|
@ -188,13 +188,25 @@ setReadState (tr_handshake * handshake, handshake_state_t state)
|
||||||
setState (handshake, state);
|
setState (handshake, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
buildHandshakeMessage (tr_handshake * handshake, uint8_t * buf)
|
buildHandshakeMessage (tr_handshake * handshake, uint8_t * buf)
|
||||||
{
|
{
|
||||||
|
const unsigned char * peer_id = NULL;
|
||||||
|
const uint8_t * torrentHash;
|
||||||
|
tr_torrent * tor;
|
||||||
|
bool success;
|
||||||
|
|
||||||
|
if ((torrentHash = tr_cryptoGetTorrentHash (handshake->crypto)))
|
||||||
|
if ((tor = tr_torrentFindFromHash (handshake->session, torrentHash)))
|
||||||
|
peer_id = tr_torrentGetPeerId (tor);
|
||||||
|
|
||||||
|
if (peer_id == NULL)
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
uint8_t * walk = buf;
|
uint8_t * walk = buf;
|
||||||
const uint8_t * torrentHash = tr_cryptoGetTorrentHash (handshake->crypto);
|
|
||||||
tr_torrent * tor = tr_torrentFindFromHash (handshake->session, torrentHash);
|
|
||||||
const unsigned char * peer_id = tr_torrentGetPeerId (tor);
|
|
||||||
|
|
||||||
memcpy (walk, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN);
|
memcpy (walk, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN);
|
||||||
walk += HANDSHAKE_NAME_LEN;
|
walk += HANDSHAKE_NAME_LEN;
|
||||||
|
@ -215,6 +227,10 @@ buildHandshakeMessage (tr_handshake * handshake, uint8_t * buf)
|
||||||
walk += PEER_ID_LEN;
|
walk += PEER_ID_LEN;
|
||||||
|
|
||||||
assert (walk - buf == HANDSHAKE_SIZE);
|
assert (walk - buf == HANDSHAKE_SIZE);
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tr_handshakeDone (tr_handshake * handshake,
|
static int tr_handshakeDone (tr_handshake * handshake,
|
||||||
|
@ -455,7 +471,8 @@ readYb (tr_handshake * handshake, struct evbuffer * inbuf)
|
||||||
/* ENCRYPT len (IA)), ENCRYPT (IA) */
|
/* ENCRYPT len (IA)), ENCRYPT (IA) */
|
||||||
{
|
{
|
||||||
uint8_t msg[HANDSHAKE_SIZE];
|
uint8_t msg[HANDSHAKE_SIZE];
|
||||||
buildHandshakeMessage (handshake, msg);
|
if (!buildHandshakeMessage (handshake, msg))
|
||||||
|
return tr_handshakeDone (handshake, false);
|
||||||
|
|
||||||
evbuffer_add_uint16 (outbuf, sizeof (msg));
|
evbuffer_add_uint16 (outbuf, sizeof (msg));
|
||||||
evbuffer_add (outbuf, msg, sizeof (msg));
|
evbuffer_add (outbuf, msg, sizeof (msg));
|
||||||
|
@ -670,7 +687,8 @@ readHandshake (tr_handshake * handshake,
|
||||||
if (!handshake->haveSentBitTorrentHandshake)
|
if (!handshake->haveSentBitTorrentHandshake)
|
||||||
{
|
{
|
||||||
uint8_t msg[HANDSHAKE_SIZE];
|
uint8_t msg[HANDSHAKE_SIZE];
|
||||||
buildHandshakeMessage (handshake, msg);
|
if (!buildHandshakeMessage (handshake, msg))
|
||||||
|
return tr_handshakeDone (handshake, false);
|
||||||
tr_peerIoWriteBytes (handshake->io, msg, sizeof (msg), false);
|
tr_peerIoWriteBytes (handshake->io, msg, sizeof (msg), false);
|
||||||
handshake->haveSentBitTorrentHandshake = 1;
|
handshake->haveSentBitTorrentHandshake = 1;
|
||||||
}
|
}
|
||||||
|
@ -920,7 +938,8 @@ readIA (tr_handshake * handshake,
|
||||||
/* send our handshake */
|
/* send our handshake */
|
||||||
{
|
{
|
||||||
uint8_t msg[HANDSHAKE_SIZE];
|
uint8_t msg[HANDSHAKE_SIZE];
|
||||||
buildHandshakeMessage (handshake, msg);
|
if (!buildHandshakeMessage (handshake, msg))
|
||||||
|
return tr_handshakeDone (handshake, false);
|
||||||
|
|
||||||
evbuffer_add (outbuf, msg, sizeof (msg));
|
evbuffer_add (outbuf, msg, sizeof (msg));
|
||||||
handshake->haveSentBitTorrentHandshake = 1;
|
handshake->haveSentBitTorrentHandshake = 1;
|
||||||
|
|
Loading…
Reference in New Issue