Changeset 931


Ignore:
Timestamp:
Sep 26, 2006, 10:36:04 PM (15 years ago)
Author:
joshe
Message:

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.

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fastresume.h

    r920 r931  
    126126    char    * path;
    127127    uint8_t * buf;
     128    uint64_t  total;
    128129
    129130    buf = malloc( FR_PROGRESS_LEN( tor ) );
     
    162163
    163164    /* Write download and upload totals */
    164     fastResumeWriteData( FR_ID_DOWNLOADED, &tor->downloaded, 8, 1, file );
    165     fastResumeWriteData( FR_ID_UPLOADED, &tor->uploaded, 8, 1, file );
     165    total = tor->downloadedCur + tor->downloadedPrev;
     166    fastResumeWriteData( FR_ID_DOWNLOADED, &total, 8, 1, file );
     167    total = tor->uploadedCur + tor->uploadedPrev;
     168    fastResumeWriteData( FR_ID_UPLOADED, &total, 8, 1, file );
    166169
    167170    fclose( file );
     
    334337                if( 8 == len)
    335338                {
    336                     if( 1 != fread( &tor->downloaded, 8, 1, file ) )
     339                    if( 1 != fread( &tor->downloadedPrev, 8, 1, file ) )
    337340                    {
    338341                        fclose( file );
     
    347350                if( 8 == len)
    348351                {
    349                     if( 1 != fread( &tor->uploaded, 8, 1, file ) )
     352                    if( 1 != fread( &tor->uploadedPrev, 8, 1, file ) )
    350353                    {
    351354                        fclose( file );
  • trunk/libtransmission/internal.h

    r920 r931  
    182182
    183183    uint64_t          date;
    184     uint64_t          downloaded;
    185     uint64_t          uploaded;
     184    uint64_t          downloadedCur;
     185    uint64_t          downloadedPrev;
     186    uint64_t          uploadedCur;
     187    uint64_t          uploadedPrev;
    186188
    187189    tr_stat_t         stats[2];
  • trunk/libtransmission/peer.c

    r926 r931  
    432432            tr_rcTransferred( tor->globalUpload, ret );
    433433
    434             tor->uploaded  += ret;
    435             peer->outTotal += ret;
    436             peer->outDate   = tr_date();
     434            tor->uploadedCur += ret;
     435            peer->outTotal   += ret;
     436            peer->outDate     = tr_date();
    437437
    438438            /* In case this block is done, you may have messages
  • trunk/libtransmission/peerparse.h

    r788 r931  
    273273    }
    274274
    275     tor->downloaded += r->length;
     275    tor->downloadedCur += r->length;
    276276
    277277    block = tr_block( r->index, r->begin );
  • trunk/libtransmission/tracker.c

    r920 r931  
    5252    int            bindPort;
    5353    int            newPort;
    54 
    55     uint64_t       download;
    56     uint64_t       upload;
    5754};
    5855
     
    7875    tc->bindPort = *(tor->bindPort);
    7976    tc->newPort  = -1;
    80 
    81     tc->download = tor->downloaded;
    82     tc->upload   = tor->uploaded;
    8377
    8478    return tc;
     
    244238    uint64_t       up;
    245239
    246     assert( tor->downloaded >= tc->download && tor->uploaded >= tc->upload );
    247     down = tor->downloaded - tc->download;
    248     up = tor->uploaded - tc->upload;
     240    down = tor->downloadedCur;
     241    up = tor->uploadedCur;
    249242    if( tc->started )
    250243    {
     
    480473    {
    481474        tc->started  = 1;
    482         tc->download = tor->downloaded;
    483         tc->upload   = tor->uploaded;
    484475    }
    485476
  • trunk/libtransmission/transmission.c

    r929 r931  
    393393    }
    394394
     395    tor->downloadedPrev += tor->downloadedCur;
     396    tor->downloadedCur   = 0;
     397    tor->uploadedPrev   += tor->uploadedCur;
     398    tor->uploadedCur     = 0;
     399
    395400    tor->status  = TR_STATUS_CHECK;
    396401    tor->tracker = tr_trackerInit( tor );
     
    541546    }
    542547
    543     s->downloaded = tor->downloaded;
    544     s->uploaded   = tor->uploaded;
     548    s->downloaded = tor->downloadedCur + tor->downloadedPrev;
     549    s->uploaded   = tor->uploadedCur   + tor->uploadedPrev;
    545550
    546551    tr_lockUnlock( &tor->lock );
Note: See TracChangeset for help on using the changeset viewer.