From f0257abb14423de5ee24444360fbb474555ef3cf Mon Sep 17 00:00:00 2001 From: Gert Doering Date: Tue, 16 Aug 2011 20:05:13 +0200 Subject: [PATCH] For all accesses to "struct route_list * rl", check first that rl is non-NULL In IPv4-only mode, this cannot happen, but if IPv6 is enabled and a servers pushes IPv6 routes and no IPv4 routes -> crash boom. Signed-off-by: Gert Doering Acked-By: David Sommerseth Signed-off-by: David Sommerseth --- route.c | 16 ++++++++++------ route.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/route.c b/route.c index 4ffb6f51a..f91edda0c 100644 --- a/route.c +++ b/route.c @@ -808,7 +808,7 @@ redirect_default_route_to_vpn (struct route_list *rl, const struct tuntap *tt, u { const char err[] = "NOTE: unable to redirect default gateway --"; - if (rl->flags & RG_ENABLE) + if ( rl && rl->flags & RG_ENABLE ) { if (!(rl->spec.flags & RTSA_REMOTE_ENDPOINT)) { @@ -917,7 +917,7 @@ redirect_default_route_to_vpn (struct route_list *rl, const struct tuntap *tt, u static void undo_redirect_default_route_to_vpn (struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es) { - if (rl->iflags & RL_DID_REDIRECT_DEFAULT_GATEWAY) + if ( rl && rl->iflags & RL_DID_REDIRECT_DEFAULT_GATEWAY ) { /* delete remote host route */ if (rl->iflags & RL_DID_LOCAL) @@ -987,7 +987,7 @@ void add_routes (struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es) { redirect_default_route_to_vpn (rl, tt, flags, es); - if (!(rl->iflags & RL_ROUTES_ADDED)) + if ( rl && !(rl->iflags & RL_ROUTES_ADDED) ) { int i; @@ -1031,19 +1031,23 @@ void delete_routes (struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es) { - if (rl->iflags & RL_ROUTES_ADDED) + if ( rl && rl->iflags & RL_ROUTES_ADDED ) { int i; for (i = rl->n - 1; i >= 0; --i) { - const struct route *r = &rl->routes[i]; + struct route * r = &rl->routes[i]; delete_route (r, tt, flags, &rl->rgi, es); } rl->iflags &= ~RL_ROUTES_ADDED; } undo_redirect_default_route_to_vpn (rl, tt, flags, es); - clear_route_list (rl); + + if ( rl ) + { + clear_route_list (rl); + } if ( rl6 && rl6->routes_added ) { diff --git a/route.h b/route.h index f900d3e0a..995347889 100644 --- a/route.h +++ b/route.h @@ -328,7 +328,7 @@ route_list_vpn_gateway_needed (const struct route_list *rl) static inline int route_did_redirect_default_gateway(const struct route_list *rl) { - return BOOL_CAST(rl->iflags & RL_DID_REDIRECT_DEFAULT_GATEWAY); + return rl && BOOL_CAST(rl->iflags & RL_DID_REDIRECT_DEFAULT_GATEWAY); } #endif -- 2.47.2