mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Bug 1071: Fix null-ptr crash in get_dom_node_child
struct dom_node contains a union that contains various structs that have members of type struct dom_node * in them. get_dom_node_list_by_type returns the address (struct dom_node **) of one of those members, or NULL. However the member itself can also be NULL if no nodes have been added to the list and the list has thus not yet been allocated. (add_to_dom_node_list lazily allocates the lists.) get_dom_node_child did not expect a null pointer there and crashed, as shown in bug 1071. Fix by adding a check so that it treats a NULL list as an empty list.
This commit is contained in:
parent
22fe77d14f
commit
8465b19d0c
@ -295,7 +295,8 @@ get_dom_node_child(struct dom_node *parent, enum dom_node_type type,
|
||||
int index;
|
||||
|
||||
list = get_dom_node_list_by_type(parent, type);
|
||||
if (!list) return NULL;
|
||||
if (!list) return NULL; /* parent doesn't support this type */
|
||||
if (!*list) return NULL; /* list is empty and not yet allocated */
|
||||
|
||||
foreach_dom_node (*list, node, index) {
|
||||
if (node->type != type)
|
||||
|
Loading…
Reference in New Issue
Block a user