1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-03 08:07:17 -05:00

Fix crashes with various bogus BitTorrent URLs

... mainly bittorrent:// and bittorrent://x

The BitTorrent URL is supposed to contain an embedded URL pointing to a
metainfo file. If this is not the case a "custom" error message will be
shown. Also fixes calling of free_list() on an uninitialized list.

Closes bug 729.
This commit is contained in:
Jonas Fonseca 2006-11-06 16:23:20 +01:00
parent f000543c03
commit b61d8d06d9
3 changed files with 10 additions and 4 deletions

View File

@ -122,6 +122,7 @@ struct s_msg_dsc {
{S_BITTORRENT_ERROR, N_("BitTorrent error")}, {S_BITTORRENT_ERROR, N_("BitTorrent error")},
{S_BITTORRENT_METAINFO, N_("The BitTorrent metainfo file contained errors")}, {S_BITTORRENT_METAINFO, N_("The BitTorrent metainfo file contained errors")},
{S_BITTORRENT_TRACKER, N_("The tracker requesting failed")}, {S_BITTORRENT_TRACKER, N_("The tracker requesting failed")},
{S_BITTORRENT_BAD_URL, N_("The BitTorrent URL does not point to a valid URL")},
#endif #endif
{0, NULL} {0, NULL}

View File

@ -104,6 +104,7 @@ enum connection_state {
S_BITTORRENT_ERROR = -100800, S_BITTORRENT_ERROR = -100800,
S_BITTORRENT_METAINFO = -100801, S_BITTORRENT_METAINFO = -100801,
S_BITTORRENT_TRACKER = -100802, S_BITTORRENT_TRACKER = -100802,
S_BITTORRENT_BAD_URL = -100803,
}; };
unsigned char *get_state_message(enum connection_state state, struct terminal *term); unsigned char *get_state_message(enum connection_state state, struct terminal *term);

View File

@ -284,6 +284,10 @@ init_bittorrent_connection(struct connection *conn)
bittorrent->conn = conn; bittorrent->conn = conn;
bittorrent->tracker.timer = TIMER_ID_UNDEF; bittorrent->tracker.timer = TIMER_ID_UNDEF;
/* Initialize here so that error handling can safely call
* free_list on it. */
init_list(bittorrent->meta.files);
return bittorrent; return bittorrent;
} }
@ -377,7 +381,7 @@ bittorrent_metainfo_callback(void *data, enum connection_state state,
void void
bittorrent_protocol_handler(struct connection *conn) bittorrent_protocol_handler(struct connection *conn)
{ {
struct uri *uri; struct uri *uri = NULL;
struct bittorrent_connection *bittorrent; struct bittorrent_connection *bittorrent;
bittorrent = init_bittorrent_connection(conn); bittorrent = init_bittorrent_connection(conn);
@ -386,11 +390,11 @@ bittorrent_protocol_handler(struct connection *conn)
return; return;
} }
assert(conn->uri->datalen); if (conn->uri->datalen)
uri = get_uri(conn->uri->data, 0); uri = get_uri(conn->uri->data, 0);
if (!uri) { if (!uri) {
abort_connection(conn, S_OUT_OF_MEM); abort_connection(conn, S_BITTORRENT_BAD_URL);
return; return;
} }