Changeset 10533


Ignore:
Timestamp:
Apr 27, 2010, 3:58:25 AM (11 years ago)
Author:
charles
Message:

(trunk libT) #3041 "Blocklist - bad peers decreases after update; corrupt error messages" -- better error messages when fed unprintable characters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/blocklist.c

    r9868 r10533  
    1111 */
    1212
     13#include <ctype.h> /* isprint() */
    1314#include <stdio.h>
    14 #include <stdlib.h> /* free */
     15#include <stdlib.h> /* free() */
    1516#include <string.h>
    1617
     
    235236    FILE *       out;
    236237    char *       line;
    237     int          lineCount = 0;
     238    int          inCount = 0;
     239    int          outCount = 0;
    238240    const char * err_fmt = _( "Couldn't read \"%1$s\": %2$s" );
    239241
     
    263265    while( !fggets( &line, in ) )
    264266    {
     267        const char * pch;
    265268        char * rangeBegin;
    266269        char * rangeEnd;
     
    268271        tr_address  addr;
    269272        struct tr_ip_range range;
     273
     274        ++inCount;
     275
     276        for( pch=line; pch && *pch; ++pch )
     277            if( !isprint( *pch ) )
     278                break;
     279        if( !pch || *pch ) {
     280            tr_err( "skipping line #%d which contains nonprintable characters\n", inCount );
     281            free( line );
     282            continue;
     283        }
    270284
    271285        rangeBegin = strrchr( line, ':' );
     
    297311        }
    298312
    299         ++lineCount;
     313        ++outCount;
    300314    }
    301315
    302316    {
    303317        char * base = tr_basename( b->filename );
    304         tr_inf( _( "Blocklist \"%1$s\" updated with %2$'d entries" ), base, lineCount );
     318        tr_inf( _( "Blocklist \"%1$s\" updated with %2$'d entries" ), base, outCount );
    305319        tr_free( base );
    306320    }
     
    312326    blocklistLoad( b );
    313327
    314     return lineCount;
    315 }
    316 
     328    return outCount;
     329}
     330
Note: See TracChangeset for help on using the changeset viewer.