Commit d15c0507 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

check map tag size in create functions too, for consistency, i think we should...

check map tag size in create functions too, for consistency, i think we should indeed remove the direct map access and constructor, see comment in ticket 129


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1668 e5f2f494-b856-4b98-b285-d166d9295462
parent e250b4e9
......@@ -249,6 +249,12 @@ Element::create(const std::vector<ElementPtr>& v) {
ElementPtr
Element::create(const std::map<std::string, ElementPtr>& m) {
for (std::map<std::string, ElementPtr>::const_iterator it = m.begin();
it != m.end(); ++it) {
if ((*it).first.length() > 255) {
isc_throw(TypeError, "Map tag is too long");
}
}
try {
return ElementPtr(new MapElement(m));
} catch (std::bad_alloc) {
......
......@@ -211,15 +211,25 @@ TEST(Element, MapElement) {
"9123456789abcdefa123456789abcdefb123456789abcdef"
"c123456789abcdefd123456789abcdefe123456789abcdef"
"f123456789abcde");
std::map<std::string, ElementPtr> long_maptag_map;
EXPECT_EQ(255, long_maptag.length()); // check prerequisite
el = Element::createFromString("{ \"" + long_maptag + "\": \"bar\"}");
EXPECT_EQ("bar", el->find(long_maptag)->stringValue());
long_maptag_map[long_maptag] = Element::create("bar");
el = Element::create(long_maptag_map);
EXPECT_EQ("bar", el->find(long_maptag)->stringValue());
// A one-byte longer tag should trigger an exception.
long_maptag.push_back('f');
EXPECT_THROW(Element::createFromString("{ \"" + long_maptag +
"\": \"bar\"}"),
ParseError);
long_maptag_map[long_maptag] = Element::create("bar");
EXPECT_THROW(Element::create(long_maptag_map), TypeError);
}
TEST(Element, to_and_from_wire) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment