From 6c6ec00251f0ac977371cdff6771870c5aacd280 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 29 Jun 2023 23:59:54 +0200 Subject: [PATCH] Handle failures when loading connection history. --- profiler/src/ConnectionHistory.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/profiler/src/ConnectionHistory.cpp b/profiler/src/ConnectionHistory.cpp index 074426b6..19007bd1 100644 --- a/profiler/src/ConnectionHistory.cpp +++ b/profiler/src/ConnectionHistory.cpp @@ -15,20 +15,25 @@ ConnectionHistory::ConnectionHistory() if( !f ) return; 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= 1024 ) goto err; char tmp[1024]; - fread( tmp, 1, ssz, f ); - fread( &cnt, 1, sizeof( cnt ), f ); + if( fread( tmp, 1, ssz, f ) != ssz ) goto err; + if( fread( &cnt, 1, sizeof( cnt ), f ) != sizeof( cnt ) ) goto err; m_connHistMap.emplace( std::string( tmp, tmp+ssz ), cnt ); } fclose( f ); Rebuild(); + return; + +err: + fclose( f ); + m_connHistMap.clear(); } ConnectionHistory::~ConnectionHistory()