Skip to content

Commit

Permalink
fixed infinite loops (#4200)
Browse files Browse the repository at this point in the history
- fixed infinite loops in config utils operation with broken streams
- added tests

Co-authored-by: Andrey Masloboev <amasloboev@topcon.com>
  • Loading branch information
andreymasloboev and Andrey Masloboev authored Oct 19, 2023
1 parent 701c8da commit feee165
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Util/src/IniFileConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 4 additions & 0 deletions Util/src/PropertyFileConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
12 changes: 12 additions & 0 deletions Util/testsuite/src/IniFileConfigurationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}


Expand Down
12 changes: 12 additions & 0 deletions Util/testsuite/src/PropertyFileConfigurationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}


Expand Down

0 comments on commit feee165

Please sign in to comment.