From 2d6cd71f821952c57e91c0c7bd82b6218ba07c51 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Wed, 20 Dec 2017 12:21:39 +0100 Subject: [PATCH] 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 --- package/gluon-radv-filterd/src/gluon-radv-filterd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package/gluon-radv-filterd/src/gluon-radv-filterd.c b/package/gluon-radv-filterd/src/gluon-radv-filterd.c index 47e408a8..77a0f4ce 100644 --- a/package/gluon-radv-filterd/src/gluon-radv-filterd.c +++ b/package/gluon-radv-filterd/src/gluon-radv-filterd.c @@ -290,6 +290,9 @@ static struct router *router_add(const struct ether_addr *mac) { struct router *router; router = malloc(sizeof(*router)); + if (!router) + return NULL; + router->src = *mac; router->next = G.routers; G.routers = router; @@ -304,6 +307,8 @@ static void router_update(const struct ether_addr *mac, uint16_t timeout) { router = router_find_src(mac); if (!router) router = router_add(mac); + if (!router) + return; router->eol = time(NULL) + timeout; }