gluon-radv-filterd: Handle malloc errors

The allocation of a new router object can fail. It must therefore be
handled to avoid segfaults.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
This commit is contained in:
Sven Eckelmann 2017-12-20 12:21:39 +01:00 committed by Jan-Philipp Litza
parent 7014d9eb14
commit 2d6cd71f82
No known key found for this signature in database
GPG Key ID: 1FB658053CE27196

View File

@ -290,6 +290,9 @@ static struct router *router_add(const struct ether_addr *mac) {
struct router *router; struct router *router;
router = malloc(sizeof(*router)); router = malloc(sizeof(*router));
if (!router)
return NULL;
router->src = *mac; router->src = *mac;
router->next = G.routers; router->next = G.routers;
G.routers = router; G.routers = router;
@ -304,6 +307,8 @@ static void router_update(const struct ether_addr *mac, uint16_t timeout) {
router = router_find_src(mac); router = router_find_src(mac);
if (!router) if (!router)
router = router_add(mac); router = router_add(mac);
if (!router)
return;
router->eol = time(NULL) + timeout; router->eol = time(NULL) + timeout;
} }