Handle failures when loading connection history.

This commit is contained in:
Bartosz Taudul 2023-06-29 23:59:54 +02:00
parent 57bd63dab6
commit 6c6ec00251
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -15,20 +15,25 @@ ConnectionHistory::ConnectionHistory()
if( !f ) return; if( !f ) return;
uint64_t sz; uint64_t sz;
fread( &sz, 1, sizeof( sz ), f ); if( fread( &sz, 1, sizeof( sz ), f ) != sizeof( sz ) ) goto err;
for( uint64_t i=0; i<sz; i++ ) for( uint64_t i=0; i<sz; i++ )
{ {
uint64_t ssz, cnt; uint64_t ssz, cnt;
fread( &ssz, 1, sizeof( ssz ), f ); if( fread( &ssz, 1, sizeof( ssz ), f ) != sizeof( ssz ) ) goto err;
assert( ssz < 1024 ); if( ssz >= 1024 ) goto err;
char tmp[1024]; char tmp[1024];
fread( tmp, 1, ssz, f ); if( fread( tmp, 1, ssz, f ) != ssz ) goto err;
fread( &cnt, 1, sizeof( cnt ), f ); if( fread( &cnt, 1, sizeof( cnt ), f ) != sizeof( cnt ) ) goto err;
m_connHistMap.emplace( std::string( tmp, tmp+ssz ), cnt ); m_connHistMap.emplace( std::string( tmp, tmp+ssz ), cnt );
} }
fclose( f ); fclose( f );
Rebuild(); Rebuild();
return;
err:
fclose( f );
m_connHistMap.clear();
} }
ConnectionHistory::~ConnectionHistory() ConnectionHistory::~ConnectionHistory()