mirror of
https://github.com/boostorg/program_options.git
synced 2026-07-21 13:33:30 +00:00
Fix UB on empty section header [] in config file parser (#158)
This commit is contained in:
@@ -97,6 +97,8 @@ namespace boost { namespace program_options { namespace detail {
|
||||
// Handle section name
|
||||
if (*s.begin() == '[' && *s.rbegin() == ']') {
|
||||
m_prefix = s.substr(1, s.size()-2);
|
||||
if (m_prefix.empty())
|
||||
boost::throw_exception(invalid_config_file_syntax(s, invalid_syntax::unrecognized_line));
|
||||
if (*m_prefix.rbegin() != '.')
|
||||
m_prefix += '.';
|
||||
}
|
||||
|
||||
@@ -298,6 +298,11 @@ void test_config_file(const char* config_file)
|
||||
check_value(a2[4], "m1.v1", "1");
|
||||
check_value(a2[5], "m1.v2", "2");
|
||||
check_value(a2[6], "m1.v3", "3");
|
||||
|
||||
// Test that an empty section header [] is rejected as invalid syntax (issue #156)
|
||||
const char content_empty_section[] = "gv1 = 0\n[]\nv1 = 1\n";
|
||||
stringstream ss_empty(content_empty_section);
|
||||
BOOST_CHECK_THROW(parse_config_file(ss_empty, desc), invalid_config_file_syntax);
|
||||
}
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
|
||||
Reference in New Issue
Block a user