From 181b9ed905b6d18f15436d8886fd1061ab5e64eb Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 3 Dec 2008 01:25:45 +0000 Subject: [PATCH] (libT) extra assertions and safeguards for #1523: crash in tr_fdFileCheckout() when starting daemon --- libtransmission/inout.c | 7 +++---- libtransmission/resume.c | 9 +++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libtransmission/inout.c b/libtransmission/inout.c index 3cb6eaa18..83e26ad89 100644 --- a/libtransmission/inout.c +++ b/libtransmission/inout.c @@ -81,6 +81,7 @@ readOrWriteBytes( const tr_torrent * tor, int err; int fileExists; + assert( tor->downloadDir && *tor->downloadDir ); assert( fileIndex < info->fileCount ); assert( !file->length || ( fileOffset < file->length ) ); assert( fileOffset + buflen <= file->length ); @@ -171,11 +172,9 @@ readOrWritePiece( const tr_torrent * tor, while( buflen && !err ) { const tr_file * file = &info->files[fileIndex]; - const uint64_t bytesThisPass = MIN( buflen, - file->length - fileOffset ); + const uint64_t bytesThisPass = MIN( buflen, file->length - fileOffset ); - err = readOrWriteBytes( tor, ioMode, - fileIndex, fileOffset, buf, bytesThisPass ); + err = readOrWriteBytes( tor, ioMode, fileIndex, fileOffset, buf, bytesThisPass ); buf += bytesThisPass; buflen -= bytesThisPass; ++fileIndex; diff --git a/libtransmission/resume.c b/libtransmission/resume.c index 441524566..89f43189e 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -461,7 +461,8 @@ loadFromFile( tr_torrent * tor, } if( ( fieldsToLoad & ( TR_FR_PROGRESS | TR_FR_DOWNLOAD_DIR ) ) - && tr_bencDictFindStr( &top, KEY_DOWNLOAD_DIR, &str ) ) + && ( tr_bencDictFindStr( &top, KEY_DOWNLOAD_DIR, &str ) ) + && ( str && *str ) ) { tr_free( tor->downloadDir ); tor->downloadDir = tr_strdup( str ); @@ -561,12 +562,12 @@ setFromCtor( tr_torrent * tor, if( fields & TR_FR_DOWNLOAD_DIR ) { - const char * downloadDir; - if( !tr_ctorGetDownloadDir( ctor, mode, &downloadDir ) ) + const char * path; + if( !tr_ctorGetDownloadDir( ctor, mode, &path ) && path && *path ) { ret |= TR_FR_DOWNLOAD_DIR; tr_free( tor->downloadDir ); - tor->downloadDir = tr_strdup( downloadDir ); + tor->downloadDir = tr_strdup( path ); } }