os: Handle corner case in Xml_node::sub_node

When calling 'sub_node' on a node with no sub nodes, the Xml_node would
interpret the characters after the current node while searching for sub
nodes. The patch adds a sanity check that lets the 'sub_node' function
throw an exception when called on a node with no sub nodes.
This commit is contained in:
Norman Feske
2014-06-19 17:17:33 +02:00
parent 65e73074d9
commit 76ecfff7b6

View File

@ -621,13 +621,16 @@ namespace Genode {
*/ */
Xml_node sub_node(unsigned idx = 0U) const Xml_node sub_node(unsigned idx = 0U) const
{ {
/* look up node at specified index */ if (_num_sub_nodes > 0) {
try {
Xml_node curr_node = _sub_node(content_addr()); /* look up node at specified index */
for (; idx > 0; idx--) try {
curr_node = curr_node.next(); Xml_node curr_node = _sub_node(content_addr());
return curr_node; for (; idx > 0; idx--)
} catch (Invalid_syntax) { } curr_node = curr_node.next();
return curr_node;
} catch (Invalid_syntax) { }
}
throw Nonexistent_sub_node(); throw Nonexistent_sub_node();
} }
@ -639,13 +642,16 @@ namespace Genode {
*/ */
Xml_node sub_node(const char *type) const Xml_node sub_node(const char *type) const
{ {
/* search for sub node of specified type */ if (_num_sub_nodes > 0) {
try {
Xml_node curr_node = _sub_node(content_addr()); /* search for sub node of specified type */
for ( ; true; curr_node = curr_node.next()) try {
if (curr_node.has_type(type)) Xml_node curr_node = _sub_node(content_addr());
return curr_node; for ( ; true; curr_node = curr_node.next())
} catch (...) { } if (curr_node.has_type(type))
return curr_node;
} catch (...) { }
}
throw Nonexistent_sub_node(); throw Nonexistent_sub_node();
} }