Skip to content

Commit bf2f338

Browse files
committed
fix socks5 issues
1 parent 5d3dc21 commit bf2f338

4 files changed

Lines changed: 130 additions & 18 deletions

File tree

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2.0.13
22

3+
* fix socks5 issues
34
* fix issue in loading v2 resume data merkle trees
45

56
2.0.12 released

include/libtorrent/proxy_base.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,10 @@ struct proxy_base
312312
{
313313
TORRENT_ASSERT(m_magic == 0x1337);
314314
if (!e) return false;
315-
std::forward<Handler>(h)(e);
316315
error_code ec;
317-
close(ec);
316+
// prevent lifetime management use-after-free
317+
close(ec); // close first
318+
std::move(h)(e); // consume
318319
return true;
319320
}
320321

include/libtorrent/socks5_stream.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class socks5_stream : public proxy_base
268268
int version = read_uint8(p);
269269
int method = read_uint8(p);
270270

271-
if (version < m_version)
271+
if (version != m_version)
272272
{
273273
std::move(h)(error_code(socks_error::unsupported_version));
274274
return;
@@ -378,7 +378,12 @@ class socks5_stream : public proxy_base
378378
else
379379
{
380380
// we either need a hostname or a valid endpoint
381-
TORRENT_ASSERT(m_remote_endpoint.address() != address());
381+
// MUST prevent malformed buf writes, endpoint corruption
382+
if (m_remote_endpoint.address() == address())
383+
{
384+
std::move(h)(boost::asio::error::invalid_argument);
385+
return;
386+
}
382387

383388
write_uint8(aux::is_v4(m_remote_endpoint) ? 1 : 4, p); // address type
384389
write_address(m_remote_endpoint.address(), p);
@@ -448,7 +453,7 @@ class socks5_stream : public proxy_base
448453

449454
if (m_version == 5)
450455
{
451-
if (version < m_version)
456+
if (version != m_version)
452457
{
453458
std::move(h)(error_code(socks_error::unsupported_version));
454459
return;

0 commit comments

Comments
 (0)