Fix blacklist crash in BitTorrent
commitd93bceb9bd6ab32c614ac20dc5c87e3af2a7f85f
authorKalle Olavi Niemitalo <kon@iki.fi>
Sun, 7 Sep 2008 03:10:52 +0000 (7 06:10 +0300)
committerKalle Olavi Niemitalo <Kalle@Astalo.kon.iki.fi>
Sun, 7 Sep 2008 03:31:36 +0000 (7 06:31 +0300)
treea32c808927944db6717398c8595626c958008579
parent7de8b9940c96f51c55c2706ed9aa6ad11257d7ee
Fix blacklist crash in BitTorrent

make_bittorrent_peer_connection() used to construct a struct uri on
the stack. This was hacky but worked nicely because the struct uri
was not really accessed after make_connection() returned.  However,
since commit a83ff1f565a4a7bc25a4b8353ee26bc1b97410e3, the struct uri
is also needed when the connection is being closed.  Valgrind shows:

Invalid read of size 2
   at 0x8100764: get_blacklist_entry (blacklist.c:33)
   by 0x8100985: del_blacklist_entry (blacklist.c:64)
   by 0x80DA579: complete_connect_socket (socket.c:448)
   by 0x80DA84A: connected (socket.c:513)
   by 0x80D0DDF: select_loop (select.c:297)
   by 0x80D00C6: main (main.c:353)
 Address 0xBEC3BFAE is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes

To fix this, allocate the struct uri on the heap instead, by
constructing a string and giving that to get_uri().  This string
cannot use the "bittorrent" URI scheme because parse_uri() does not
recognize the host and port fields in that.  (The "bittorrent" scheme
has protocol_backend.free_syntax = 1 in order to support strings like
"bittorrent:http://beta.legaltorrents.com/get/159-noisome-beasts".)
Instead, define a new "bittorrent-peer" URI scheme for this purpose.
If the user attempts to use this URI scheme, its handler aborts the
connection with an error; but when make_bittorrent_peer_connection()
uses a bittorrent-peer URI, the handler is not called.

This change also lets get_uri() set the ipv6 flag if peer_info->ip is
an IPv6 address literal.

Reported by Witold Filipczyk.
src/network/state.c
src/network/state.h
src/protocol/bittorrent/connection.c
src/protocol/bittorrent/connection.h
src/protocol/bittorrent/peerconnect.c
src/protocol/protocol.c
src/protocol/protocol.h