Fix segfault if rtnl_route_get_gateway returns NULL
authorJoachim Breitner <mail@joachim-breitner.de>
Fri, 19 Mar 2010 18:55:34 +0000 (19:55 +0100)
committerJoachim Breitner <mail@joachim-breitner.de>
Fri, 19 Mar 2010 18:55:34 +0000 (19:55 +0100)
libnss_gw_name.c

index 728d9fa..f999cd9 100644 (file)
@@ -72,7 +72,14 @@ find_gateway() {
                if (rtnl_route_get_dst_len(route) != 0) continue;
                
                // Found a gateway
-               gw = nl_addr_clone(rtnl_route_get_gateway (route));
+               struct nl_addr *gw_ = rtnl_route_get_gateway(route);
+               if (!gw_) continue;
+
+               // Clone the address, as this one will be freed with the route cache (will it?)
+               gw = nl_addr_clone(gw_);
+               if (!gw) continue;
+
+               break;
 
                //char buf[100];
                //printf("Addr: %s\n", nl_addr2str(dst,buf,100));