fixed infinite loops (#4200)

- fixed infinite loops in config utils operation with broken streams
- added tests

Co-authored-by: Andrey Masloboev <amasloboev@topcon.com>
This commit is contained in:
Andrey Masloboev 2023-10-19 14:26:44 +03:00 committed by GitHub
parent 701c8dae2d
commit feee1650e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 0 deletions

View File

@ -65,6 +65,10 @@ void IniFileConfiguration::load(std::istream& istr)
_sectionKey.clear();
while (!istr.eof())
{
if(istr.fail())
{
throw Poco::IOException("Broken input stream");
}
parseLine(istr);
}
}

View File

@ -58,6 +58,10 @@ void PropertyFileConfiguration::load(std::istream& istr)
clear();
while (!istr.eof())
{
if(istr.fail())
{
throw Poco::IOException("Broken input stream");
}
parseLine(istr);
}
}

View File

@ -87,6 +87,18 @@ void IniFileConfigurationTest::testLoad()
assertTrue (std::find(keys.begin(), keys.end(), "section1") != keys.end());
assertTrue (std::find(keys.begin(), keys.end(), "section 2") != keys.end());
assertTrue (std::find(keys.begin(), keys.end(), "Prop1") == keys.end());
std::istringstream istr_err(iniFile);
istr_err.putback(std::ios_base::failbit);
try
{
AutoPtr<IniFileConfiguration> pConf_err = new IniFileConfiguration(istr_err);
}
catch (Poco::IOException& exc)
{
std::string s(exc.message());
assertTrue (s == "Broken input stream");
}
}

View File

@ -85,6 +85,18 @@ void PropertyFileConfigurationTest::testLoad()
catch (NotFoundException&)
{
}
std::istringstream istr_err(propFile);
istr_err.putback(std::ios_base::failbit);
try
{
AutoPtr<PropertyFileConfiguration> pConf_err = new PropertyFileConfiguration(istr_err);
}
catch (Poco::IOException& exc)
{
std::string s(exc.message());
assertTrue (s == "Broken input stream");
}
}