From 2d3718151d4f4248618f5c9f3ea5765f91f39eef Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Fri, 16 Jan 2009 04:17:22 +0000 Subject: Fix a pointer arithmetic issue leading to incorrect peer data being copied. Allocate correct size for debugbuffer. Expect exact values on find keywords, not only prefix match. --- opentracker.c | 2 +- ot_http.c | 4 ++-- scan_urlencoded_query.c | 2 +- trackerlogic.c | 5 ++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/opentracker.c b/opentracker.c index fd1698a..6cca576 100644 --- a/opentracker.c +++ b/opentracker.c @@ -201,7 +201,7 @@ static void server_mainloop( ) { ws.inbuf = malloc( G_INBUF_SIZE ); ws.outbuf = malloc( G_OUTBUF_SIZE ); #ifdef _DEBUG_HTTPERROR - ws.debugbuf= malloc( G_INBUF_SIZE ); + ws.debugbuf= malloc( G_DEBUGBUF_SIZE ); #endif if( !ws.inbuf || !ws.outbuf ) panic( "Initializing worker failed" ); diff --git a/ot_http.c b/ot_http.c index 3ccdb84..bc3aef0 100644 --- a/ot_http.c +++ b/ot_http.c @@ -247,7 +247,7 @@ static ssize_t http_handle_fullscrape( const int64 sock, struct ot_workstruct *w stats_issue_event( EVENT_FULLSCRAPE_REQUEST, 0, (uintptr_t)cookie->ip ); #ifdef _DEBUG_HTTPERROR -write( 2, ws->debugbuf, G_DEBUGBUF_SIZE ); + fprintf( stderr, "%s", ws->debugbuf ); #endif /* Pass this task to the worker thread */ @@ -299,7 +299,7 @@ static ssize_t http_handle_scrape( const int64 sock, struct ot_workstruct *ws, c return ws->reply_size; } -static ot_keywords keywords_announce[] = { { "port", 1 }, { "left", 2 }, { "event", 3 }, { "numwant", 4 }, { "compact", 5 }, { "info_hash", 6 }, +static ot_keywords keywords_announce[] = { { "port", 1 }, { "left", 2 }, { "event", 3 }, { "numwant", 4 }, { "compact", 5 }, { "compact6", 5 }, { "info_hash", 6 }, #ifdef WANT_IP_FROM_QUERY_STRING { "ip", 7 }, #endif diff --git a/scan_urlencoded_query.c b/scan_urlencoded_query.c index d8786a1..721dd44 100644 --- a/scan_urlencoded_query.c +++ b/scan_urlencoded_query.c @@ -75,7 +75,7 @@ int scan_find_keywords( const ot_keywords * keywords, char **string, SCAN_SEARCH if( match_length == 0 ) return -3; while( keywords->key ) { - if( !memcmp( keywords->key, deststring, match_length ) ) + if( !memcmp( keywords->key, deststring, match_length ) && !keywords->key[match_length] ) return keywords->value; keywords++; } diff --git a/trackerlogic.c b/trackerlogic.c index d07851e..3ca266a 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -129,7 +129,7 @@ size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_ OT_PEERFLAG( peer ) |= PEER_FLAG_COMPLETED; } - *peer_dest = *peer; + memcpy( peer_dest, peer, sizeof(ot_peer) ); #ifdef WANT_SYNC if( proto == FLAG_MCA ) { mutex_bucket_unlock_by_hash( hash, delta_torrentcount ); @@ -156,8 +156,7 @@ static size_t return_peers_all( ot_peerlist *peer_list, char *reply ) { ot_peer * peers = (ot_peer*)bucket_list[bucket].data; size_t peer_count = bucket_list[bucket].size; while( peer_count-- ) { - memcpy(r,peers,OT_PEER_COMPARE_SIZE); - peers+=sizeof(ot_peer); + memcpy(r,peers++,OT_PEER_COMPARE_SIZE); r+=OT_PEER_COMPARE_SIZE; } } -- cgit v1.2.3