1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

Bug 1071: Add NULL check in get_dom_node_list_index

If the parent parameter of get_dom_node_list_index referred to a node
that did not have children, then get_dom_node_list called by it could
return the address of a null pointer, and get_dom_node_list_index would
then pass that null pointer to get_dom_node_list_pos, which would crash.
That would be the same kind of crash as the one in get_dom_node_child.
It never happened in practice though: because all calls are in the form
get_dom_node_list_index(node->parent, node), the list must contain at
least the given node, and the pointer cannot be null.  The documentation
of get_dom_node_list_index allows arbitrary nodes as arguments however,
so it's best to add a check.
This commit is contained in:
Kalle Olavi Niemitalo 2009-04-04 22:41:43 +03:00 committed by Kalle Olavi Niemitalo
parent 0c1a27ee99
commit b7f45ca80b

View File

@ -247,7 +247,7 @@ get_dom_node_list_index(struct dom_node *parent, struct dom_node *node)
{
struct dom_node_list **list = get_dom_node_list(parent, node);
return list ? get_dom_node_list_pos(*list, node) : -1;
return (list && *list) ? get_dom_node_list_pos(*list, node) : -1;
}
struct dom_node *