1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-12 07:03:44 +00:00

Fix possible uint64_t underflow which could cause insanely huge (16,000,000 TB)

upload and/or download totals to be reported to the tracker.
This commit is contained in:
Josh Elsasser 2006-09-26 22:36:04 +00:00
parent 5b58c7aec0
commit f7c3910a79
6 changed files with 24 additions and 23 deletions

View file

@ -125,6 +125,7 @@ static void fastResumeSave( tr_io_t * io )
int version = 1;
char * path;
uint8_t * buf;
uint64_t total;
buf = malloc( FR_PROGRESS_LEN( tor ) );
@ -161,8 +162,10 @@ static void fastResumeSave( tr_io_t * io )
free( buf );
/* Write download and upload totals */
fastResumeWriteData( FR_ID_DOWNLOADED, &tor->downloaded, 8, 1, file );
fastResumeWriteData( FR_ID_UPLOADED, &tor->uploaded, 8, 1, file );
total = tor->downloadedCur + tor->downloadedPrev;
fastResumeWriteData( FR_ID_DOWNLOADED, &total, 8, 1, file );
total = tor->uploadedCur + tor->uploadedPrev;
fastResumeWriteData( FR_ID_UPLOADED, &total, 8, 1, file );
fclose( file );
@ -333,7 +336,7 @@ static int fastResumeLoad( tr_io_t * io )
/* read download total */
if( 8 == len)
{
if( 1 != fread( &tor->downloaded, 8, 1, file ) )
if( 1 != fread( &tor->downloadedPrev, 8, 1, file ) )
{
fclose( file );
return 1;
@ -346,7 +349,7 @@ static int fastResumeLoad( tr_io_t * io )
/* read upload total */
if( 8 == len)
{
if( 1 != fread( &tor->uploaded, 8, 1, file ) )
if( 1 != fread( &tor->uploadedPrev, 8, 1, file ) )
{
fclose( file );
return 1;

View file

@ -181,8 +181,10 @@ struct tr_torrent_s
tr_peer_t * peers[TR_MAX_PEER_COUNT];
uint64_t date;
uint64_t downloaded;
uint64_t uploaded;
uint64_t downloadedCur;
uint64_t downloadedPrev;
uint64_t uploadedCur;
uint64_t uploadedPrev;
tr_stat_t stats[2];
int statCur;

View file

@ -431,9 +431,9 @@ writeBegin:
tr_rcTransferred( tor->upload, ret );
tr_rcTransferred( tor->globalUpload, ret );
tor->uploaded += ret;
peer->outTotal += ret;
peer->outDate = tr_date();
tor->uploadedCur += ret;
peer->outTotal += ret;
peer->outDate = tr_date();
/* In case this block is done, you may have messages
pending. Send them before we start the next block */

View file

@ -272,7 +272,7 @@ static inline int parsePiece( tr_torrent_t * tor, tr_peer_t * peer,
return 1;
}
tor->downloaded += r->length;
tor->downloadedCur += r->length;
block = tr_block( r->index, r->begin );
if( tr_cpBlockIsComplete( tor->completion, block ) )

View file

@ -51,9 +51,6 @@ struct tr_tracker_s
int bindPort;
int newPort;
uint64_t download;
uint64_t upload;
};
static tr_http_t * getQuery ( tr_tracker_t * tc );
@ -78,9 +75,6 @@ tr_tracker_t * tr_trackerInit( tr_torrent_t * tor )
tc->bindPort = *(tor->bindPort);
tc->newPort = -1;
tc->download = tor->downloaded;
tc->upload = tor->uploaded;
return tc;
}
@ -243,9 +237,8 @@ static tr_http_t * getQuery( tr_tracker_t * tc )
uint64_t down;
uint64_t up;
assert( tor->downloaded >= tc->download && tor->uploaded >= tc->upload );
down = tor->downloaded - tc->download;
up = tor->uploaded - tc->upload;
down = tor->downloadedCur;
up = tor->uploadedCur;
if( tc->started )
{
event = "&event=started";
@ -479,8 +472,6 @@ nodict:
else if( 0 < tc->newPort )
{
tc->started = 1;
tc->download = tor->downloaded;
tc->upload = tor->uploaded;
}
cleanup:

View file

@ -392,6 +392,11 @@ void tr_torrentStart( tr_torrent_t * tor )
torrentReallyStop( tor );
}
tor->downloadedPrev += tor->downloadedCur;
tor->downloadedCur = 0;
tor->uploadedPrev += tor->uploadedCur;
tor->uploadedCur = 0;
tor->status = TR_STATUS_CHECK;
tor->tracker = tr_trackerInit( tor );
@ -540,8 +545,8 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor )
(float) inf->totalSize / s->rateDownload / 1024.0;
}
s->downloaded = tor->downloaded;
s->uploaded = tor->uploaded;
s->downloaded = tor->downloadedCur + tor->downloadedPrev;
s->uploaded = tor->uploadedCur + tor->uploadedPrev;
tr_lockUnlock( &tor->lock );