Bug #4489
closed
ConfigFile::parseNumber<unsigned>() doesn't reject negative arguments
Added by Davide Pesavento almost 7 years ago.
Updated over 4 years ago.
Description
For instance, ConfigFile::parseNumber<uint16_t>
is used in the TCP and UDP factories to parse the port number. Negative port numbers are accepted instead of raising an exception.
The following test case should pass but currently fails.
BOOST_AUTO_TEST_CASE(BadPort)
{
const std::string CONFIG = R"CONFIG(
face_system
{
udp
{
port -1
}
}
)CONFIG";
BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
}
Related issues
1 (1 open — 0 closed)
name::Component::fromEscapedString
solved a similar problem with the following code:
long parsedType = std::strtol(input.data(), nullptr, 10);
if (parsedType < tlv::NameComponentMin || parsedType > tlv::NameComponentMax ||
to_string(parsedType).size() != equalPos) {
BOOST_THROW_EXCEPTION(Error("Incorrect TLV-TYPE in NameComponent URI"));
}
It converts the parsed number back to a string, and checks that this string equals the input string.
Adopting the same logic to ConfigFile::parseNumber
implies that numbers written in non-canonical form, such as 06363
or +6363
, would be rejected. I think it's okay to require numbers to be in canonical form.
Junxiao Shi wrote:
Adopting the same logic to ConfigFile::parseNumber
implies that numbers written in non-canonical form, such as 06363
or +6363
, would be rejected.
06363
would be interpreted as octal, wouldn't it?
I think it's okay to require numbers to be in canonical form.
I think so too.
This seems to have been fixed somewhat recently in boost, probably in version 1.68.0 (Aug 2018), although I couldn't isolate the exact commit (boost::property_tree
hasn't been touched since Oct 2016).
- Status changed from New to In Progress
- Assignee set to Eric Newberry
Ok. Boost probably delegates the actual parsing to some lower-level C/C++ library function, which may have accidentally changed behavior in 10.14, and reverted back to the previous behavior in 10.15. Just a guess...
- Related to Task #5091: Switch NFD configuration file format added
- Status changed from In Progress to Code review
- % Done changed from 0 to 100
- Status changed from Code review to Closed
- Target version set to 22.02
Also available in: Atom
PDF