1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

#5456: Fix encrypted communication with libevent 2.1.x

Recent versions of libevent changed the semantics of `evbuffer_ptr_set`
function in a way that it succeeds if pointer is set right after the end
of the buffer. This caused `tr_cryptoEncrypt` and `tr_cryptoDecrypt` to
be called twice for last buffer chunk since no checks for `evbuffer_peek`
return value were made while it was returning 0 on last loop cycle,
leaving iovec unchanged.
This commit is contained in:
Mike Gelfand 2015-06-17 20:32:33 +00:00
parent 58312e6c16
commit 45b73a7866

View file

@ -1060,7 +1060,8 @@ maybeEncryptBuffer (tr_peerIo * io, struct evbuffer * buf)
struct evbuffer_iovec iovec; struct evbuffer_iovec iovec;
evbuffer_ptr_set (buf, &pos, 0, EVBUFFER_PTR_SET); evbuffer_ptr_set (buf, &pos, 0, EVBUFFER_PTR_SET);
do { do {
evbuffer_peek (buf, -1, &pos, &iovec, 1); if (evbuffer_peek (buf, -1, &pos, &iovec, 1) != 1)
break;
tr_cryptoEncrypt (&io->crypto, iovec.iov_len, iovec.iov_base, iovec.iov_base); tr_cryptoEncrypt (&io->crypto, iovec.iov_len, iovec.iov_base, iovec.iov_base);
} while (!evbuffer_ptr_set (buf, &pos, iovec.iov_len, EVBUFFER_PTR_ADD)); } while (!evbuffer_ptr_set (buf, &pos, iovec.iov_len, EVBUFFER_PTR_ADD));
} }
@ -1147,7 +1148,8 @@ tr_peerIoReadBytesToBuf (tr_peerIo * io, struct evbuffer * inbuf, struct evbuffe
struct evbuffer_iovec iovec; struct evbuffer_iovec iovec;
evbuffer_ptr_set (outbuf, &pos, old_length, EVBUFFER_PTR_SET); evbuffer_ptr_set (outbuf, &pos, old_length, EVBUFFER_PTR_SET);
do { do {
evbuffer_peek (outbuf, byteCount, &pos, &iovec, 1); if (evbuffer_peek (outbuf, byteCount, &pos, &iovec, 1) != 1)
break;
tr_cryptoDecrypt (&io->crypto, iovec.iov_len, iovec.iov_base, iovec.iov_base); tr_cryptoDecrypt (&io->crypto, iovec.iov_len, iovec.iov_base, iovec.iov_base);
byteCount -= iovec.iov_len; byteCount -= iovec.iov_len;
} while (!evbuffer_ptr_set (outbuf, &pos, iovec.iov_len, EVBUFFER_PTR_ADD)); } while (!evbuffer_ptr_set (outbuf, &pos, iovec.iov_len, EVBUFFER_PTR_ADD));