ipv6: Fix NULL pointer dereference in ip6addr_add()

When ip6addr_add() is called for the first time, both the first_ip6
and the last_ip6 pointer are not initialized yet, i.e. contain NULL.
So writing to "last_ip6->next" is a bad idea here. Fix it so that
this value is only written when the function is not called for the
first time.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
This commit is contained in:
Thomas Huth 2016-05-02 21:55:30 +02:00 committed by Alexey Kardashevskiy
parent 8f8c4e6414
commit 8870f4400f
1 changed files with 2 additions and 1 deletions

View File

@ -330,7 +330,8 @@ int8_t ip6addr_add(struct ip6addr_list_entry *new_address)
if (first_ip6 == NULL)
first_ip6 = new_address;
last_ip6->next = new_address;
else
last_ip6->next = new_address;
last_ip6 = new_address;
last_ip6->next = NULL;