gw: fix null pointer dereferences in cost calculation
authorFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 21 Feb 2014 08:30:33 +0000 (09:30 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 21 Feb 2014 08:31:03 +0000 (09:31 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/gateway_default_handler.c

index dd962f9..dfc214f 100644 (file)
@@ -102,7 +102,7 @@ static void gw_default_choose_gateway(void) {
       bool gw_eligible_v4 = gw->ipv4
           /* && (olsr_cnf->ip_version == AF_INET || olsr_cnf->use_niit) *//* contained in gw_def_choose_new_ipv4_gw */
           && (olsr_cnf->smart_gw_allow_nat || !gw->ipv4nat);
-      if (gw_eligible_v4 && gw_cost < chosen_gw_ipv4->path_cost
+      if (gw_eligible_v4 && gw_cost < (chosen_gw_ipv4 ? chosen_gw_ipv4->path_cost : UINT64_MAX)
           && (!cost_ipv4_threshold_valid || (gw_cost < cost_ipv4_threshold))) {
         chosen_gw_ipv4 = gw;
       }
@@ -111,7 +111,7 @@ static void gw_default_choose_gateway(void) {
     if (gw_def_choose_new_ipv6_gw) {
       bool gw_eligible_v6 = gw->ipv6
           /* && olsr_cnf->ip_version == AF_INET6 *//* contained in gw_def_choose_new_ipv6_gw */;
-      if (gw_eligible_v6 && gw_cost < chosen_gw_ipv6->path_cost
+      if (gw_eligible_v6 && gw_cost < (chosen_gw_ipv6 ? chosen_gw_ipv6->path_cost : UINT64_MAX)
           && (!cost_ipv6_threshold_valid || (gw_cost < cost_ipv6_threshold))) {
         chosen_gw_ipv6 = gw;
       }