From 484be7c30c3653a2320ee255a739f4223df83134 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Wed, 5 May 2010 12:56:13 +0000 Subject: [PATCH] Make whitelist parser more robust against comments. I assumed perfectly arranged white lists until now --- ot_accesslist.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ot_accesslist.c b/ot_accesslist.c index fec09eb..00d4e97 100644 --- a/ot_accesslist.c +++ b/ot_accesslist.c @@ -53,26 +53,29 @@ static void accesslist_readfile( void ) { fprintf( stderr, "Warning: Not enough memory to allocate %zd bytes for accesslist buffer. May succeed later.\n", ( maplen / 41 ) * 20 ); return; } - + /* No use to scan if there's not enough room for another full info_hash */ map_end = map + maplen - 40; read_offs = map; /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */ - while( read_offs < map_end ) { + while( read_offs + 40 <= map_end ) { int i; for( i=0; i<(int)sizeof(ot_hash); ++i ) { - int eger = 16 * scan_fromhex( read_offs[ 2*i ] ) + scan_fromhex( read_offs[ 1 + 2*i ] ); - if( eger < 0 ) - continue; - (*info_hash)[i] = eger; + int eger1 = scan_fromhex( read_offs[ 2*i ] ); + int eger2 = scan_fromhex( read_offs[ 1 + 2*i ] ); + if( eger1 < 0 || eger2 < 0 ) + break; + (*info_hash)[i] = eger1 * 16 + eger2; } - read_offs += 40; + if( i == sizeof(ot_hash) ) { + read_offs += 40; - /* Append accesslist to accesslist vector */ - if( scan_fromhex( *read_offs ) < 0 ) - ++info_hash; + /* Append accesslist to accesslist vector */ + if( read_offs == map_end || scan_fromhex( *read_offs ) < 0 ) + ++info_hash; + } /* Find start of next line */ while( read_offs < map_end && *(read_offs++) != '\n' ); @@ -307,4 +310,4 @@ int accesslist_isblessed( ot_ip6 ip, ot_permissions permissions ) { return 0; } -const char *g_version_accesslist_c = "$Source: /home/cvsroot/opentracker/ot_accesslist.c,v $: $Revision: 1.28 $\n"; +const char *g_version_accesslist_c = "$Source: /home/cvsroot/opentracker/ot_accesslist.c,v $: $Revision: 1.29 $\n";