diff options
author | Thomas Huth <thuth@redhat.com> | 2016-05-02 21:55:29 +0200 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2016-05-05 16:11:04 +1000 |
commit | 8f8c4e64148b509d1a7a9e6bae6fd63bf0fce036 (patch) | |
tree | c0355c95b900f4df44d57f9f34c5af9ee78ce1ab /clients | |
parent | 6a70b4a73257cf97e573f5fc1599410b268496b6 (diff) | |
download | SLOF-8f8c4e64148b509d1a7a9e6bae6fd63bf0fce036.zip SLOF-8f8c4e64148b509d1a7a9e6bae6fd63bf0fce036.tar.gz SLOF-8f8c4e64148b509d1a7a9e6bae6fd63bf0fce036.tar.bz2 |
ipv6: Fix memory leak in set_ipv6_address() / ip6_create_ll_address()
The set_ipv6_address() function calls ip6_create_ll_address() to
get a link-local address. The latter function uses malloc to create
a buffer for composing that address, and returns the corresponding
poniter to the caller. However, set_ipv6_address() does not free
that buffer again, so the allocated memory is lost.
Since set_ipv6_address() already allocated space for the new IPv6
address anyway, let's fix this issue by passing the buffer from
set_ipv6_address() to ip6_create_ll_address() instead, so that
ip6_create_ll_address() does not have to allocate memory at all.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'clients')
-rw-r--r-- | clients/net-snk/app/netlib/ipv6.c | 18 | ||||
-rw-r--r-- | clients/net-snk/app/netlib/ipv6.h | 2 |
2 files changed, 6 insertions, 14 deletions
diff --git a/clients/net-snk/app/netlib/ipv6.c b/clients/net-snk/app/netlib/ipv6.c index baa5034..220fd36 100644 --- a/clients/net-snk/app/netlib/ipv6.c +++ b/clients/net-snk/app/netlib/ipv6.c @@ -77,9 +77,7 @@ void set_ipv6_address(int fd, ip6_addr_t *_own_ip6) /* If no address was passed as a parameter generate a link-local * address from our MAC address.*/ if (_own_ip6 == NULL) - memcpy(&(own_ip6->addr.addr), - ip6_create_ll_address(get_mac_address()), - IPV6_ADDR_LENGTH); + ip6_create_ll_address(get_mac_address(), &own_ip6->addr); else memcpy (&(own_ip6->addr.addr), _own_ip6, 16); @@ -225,18 +223,12 @@ uint64_t mac2eui64(const uint8_t *mac) * NET: create link-local IPv6 address * * @param own_mac MAC of NIC - * @return ll_addr pointer to newly created link-local address + * @param ll_addr pointer to link-local address which should be created */ -ip6_addr_t *ip6_create_ll_address(const uint8_t *own_mac) +void ip6_create_ll_address(const uint8_t *own_mac, ip6_addr_t *ll_addr) { - ip6_addr_t *ll_addr; - - ll_addr = malloc (sizeof (struct ip6addr_list_entry)); - memset (ll_addr, 0, IPV6_ADDR_LENGTH); - ll_addr->part.prefix |= IPV6_LL_PREFIX; - ll_addr->part.interface_id |= mac2eui64((uint8_t *) own_mac); - - return ll_addr; + ll_addr->part.prefix = IPV6_LL_PREFIX; + ll_addr->part.interface_id = mac2eui64((uint8_t *) own_mac); } /* diff --git a/clients/net-snk/app/netlib/ipv6.h b/clients/net-snk/app/netlib/ipv6.h index 72c6ee2..6565a88 100644 --- a/clients/net-snk/app/netlib/ipv6.h +++ b/clients/net-snk/app/netlib/ipv6.h @@ -150,7 +150,7 @@ void set_ipv6_address(int fd, ip6_addr_t *own_ip6); ip6_addr_t *get_ipv6_address(void); /* Create link-local address from a given Mac Address */ -ip6_addr_t * ip6_create_ll_address (const uint8_t *own_mac); +void ip6_create_ll_address (const uint8_t *own_mac, ip6_addr_t *ll_addr); /* For a given MAC calculates EUI64-Identifier.*/ uint64_t mac2eui64 (const uint8_t *mac); |