Changeset 5606


Ignore:
Timestamp:
Apr 13, 2008, 2:29:11 PM (14 years ago)
Author:
charles
Message:

#872: crash in bitfield code when loading resume files

Location:
trunk/libtransmission
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/Makefile.am

    r5585 r5606  
    2929    publish.c \
    3030    ratecontrol.c \
     31    resume.c \
    3132    session.c \
    3233    stats.c \
     
    6566    publish.h \
    6667    ratecontrol.h \
     68    resume.h \
    6769    session.h \
    6870    stats.h \
  • trunk/libtransmission/completion.c

    r5597 r5606  
    238238}
    239239
    240 void
     240tr_errno
    241241tr_cpBlockBitfieldSet( tr_completion * cp, tr_bitfield * bitfield )
    242242{
    243243    tr_block_index_t i;
    244244
    245     assert( cp != NULL );
    246     assert( bitfield != NULL );
     245    if( !cp || !bitfield || ( bitfield->len != cp->blockBitfield->len ) )
     246        return TR_ERROR_ASSERT;
    247247
    248248    tr_cpReset( cp );
    249 
    250249    for( i=0; i < cp->tor->blockCount; ++i )
    251250        if( tr_bitfieldHas( bitfield, i ) )
    252251            tr_cpBlockAdd( cp, i );
     252
     253    return 0;
    253254}
    254255
  • trunk/libtransmission/completion.h

    r5597 r5606  
    5454int              tr_cpBlockIsComplete( const tr_completion *, tr_block_index_t block );
    5555void             tr_cpBlockAdd( tr_completion *, tr_block_index_t block );
    56 void             tr_cpBlockBitfieldSet( tr_completion *, struct tr_bitfield * );
     56tr_errno         tr_cpBlockBitfieldSet( tr_completion *, struct tr_bitfield * );
    5757float            tr_cpPercentBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece );
    5858int              tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece );
  • trunk/libtransmission/fastresume.c

    r5521 r5606  
    5757#include "peer-mgr.h"
    5858#include "platform.h"
     59#include "resume.h" /* TR_FR_ bitwise enum */
    5960#include "torrent.h"
    6061#include "utils.h"
     
    116117  ( sizeof(tr_time_t) * (t)->info.fileCount )
    117118#define FR_BLOCK_BITFIELD_LEN( t ) \
    118   ( ( (t)->blockCount + 7 ) / 8 )
     119  ( ( (t)->blockCount + 7u ) / 8u )
    119120#define FR_PROGRESS_LEN( t ) \
    120121  ( FR_MTIME_LEN( t ) + FR_BLOCK_BITFIELD_LEN( t ) )
     
    427428        bitfield.len = FR_BLOCK_BITFIELD_LEN( tor );
    428429        bitfield.bits = (uint8_t*) walk;
    429         tr_cpBlockBitfieldSet( tor->completion, &bitfield );
    430 
    431         ret = TR_FR_PROGRESS;
     430        if( !tr_cpBlockBitfieldSet( tor->completion, &bitfield ) )
     431            ret = TR_FR_PROGRESS;
     432        else {
     433            tr_torrentUncheck( tor );
     434            tr_tordbg( tor, "Torrent needs to be verified" );
     435        }
    432436    }
    433437
  • trunk/libtransmission/fastresume.h

    r5066 r5606  
    2828void tr_fastResumeSave( const tr_torrent * tor );
    2929
    30 enum
    31 {
    32   TR_FR_DOWNLOADED   = (1<<0),
    33   TR_FR_UPLOADED     = (1<<1),
    34   TR_FR_CORRUPT      = (1<<2),
    35   TR_FR_PEERS        = (1<<3),
    36   TR_FR_PROGRESS     = (1<<4),
    37   TR_FR_PRIORITY     = (1<<5),
    38   TR_FR_SPEEDLIMIT   = (1<<6),
    39   TR_FR_RUN          = (1<<7),
    40   TR_FR_DESTINATION  = (1<<8),
    41   TR_FR_MAX_PEERS    = (1<<9)
    42 };
    43 
    4430/**
    4531 * Returns a bitwise-or'ed set of the data loaded from fastresume
  • trunk/libtransmission/torrent.c

    r5597 r5606  
    3030#include "completion.h"
    3131#include "crypto.h" /* for tr_sha1 */
    32 #include "fastresume.h"
     32#include "resume.h"
    3333#include "fdlimit.h" /* tr_fdFileClose */
    3434#include "metainfo.h"
     
    354354    tor->checkedPieces = tr_bitfieldNew( tor->info.pieceCount );
    355355    tr_torrentUncheck( tor );
    356     loaded = tr_fastResumeLoad( tor, ~0, ctor );
     356    loaded = tr_torrentLoadResume( tor, ~0, ctor );
    357357   
    358358    doStart = tor->isRunning;
     
    458458}
    459459
    460 /***
    461 ****
    462 ***/
    463 
    464 static void
    465 saveFastResumeNow( tr_torrent * tor )
    466 {
    467     tr_fastResumeSave( tor );
    468 }
    469 
    470460/**
    471461***
     
    477467    tr_free( tor->destination );
    478468    tor->destination = tr_strdup( path );
    479     saveFastResumeNow( tor );
     469    tr_torrentSaveResume( tor );
    480470}
    481471
     
    825815    tr_metainfoRemoveSaved( tor->handle, tor->info.hashString );
    826816
    827     tr_fastResumeRemove( tor );
     817    tr_torrentRemoveResume( tor );
    828818}
    829819
     
    922912    tr_torrentResetTransferStats( tor );
    923913    tor->cpStatus = tr_cpGetStatus( tor->completion );
    924     saveFastResumeNow( tor );
     914    tr_torrentSaveResume( tor );
    925915    tor->startDate = tr_date( );
    926916    tr_trackerStart( tor->tracker );
     
    943933    if( !tor->isRunning )
    944934    {
    945         tr_fastResumeLoad( tor, TR_FR_PROGRESS, NULL );
     935        tr_torrentLoadResume( tor, TR_FR_PROGRESS, NULL );
    946936        tor->isRunning = 1;
    947937        tr_verifyAdd( tor, checkAndStartCB );
     
    1000990
    1001991    if( !tor->isDeleting )
    1002         saveFastResumeNow( tor );
     992        tr_torrentSaveResume( tor );
    1003993    tor->isRunning = 0;
    1004994    tr_runInEventThread( tor->handle, stopTorrent, tor );
     
    10111001{
    10121002    tr_torrent * tor = vtor;
    1013     saveFastResumeNow( tor );
     1003    tr_torrentSaveResume( tor );
    10141004    tor->isRunning = 0;
    10151005    stopTorrent( tor );
     
    11131103            tr_trackerCompleted( tor->tracker );
    11141104
    1115         saveFastResumeNow( tor );
     1105        tr_torrentSaveResume( tor );
    11161106    }
    11171107
     
    11591149        tr_torrentInitFilePriority( tor, files[i], priority );
    11601150
    1161     saveFastResumeNow( tor );
     1151    tr_torrentSaveResume( tor );
    11621152    tr_torrentUnlock( tor );
    11631153}
     
    12861276    tr_torrentLock( tor );
    12871277    tr_torrentInitFileDLs( tor, files, fileCount, doDownload );
    1288     saveFastResumeNow( tor );
     1278    tr_torrentSaveResume( tor );
    12891279    tr_torrentUnlock( tor );
    12901280}
  • trunk/libtransmission/verify.c

    r5329 r5606  
    1515#include "transmission.h"
    1616#include "completion.h"
    17 #include "fastresume.h" /* tr_fastResumeSave() */
     17#include "resume.h" /* tr_torrentSaveResume() */
    1818#include "inout.h"
    1919#include "list.h"
     
    134134        if( !stopCurrent )
    135135        {
    136             tr_fastResumeSave( tor );
     136            tr_torrentSaveResume( tor );
    137137            fireCheckDone( tor, currentNode.verify_done_cb );
    138138        }
Note: See TracChangeset for help on using the changeset viewer.