]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
For all accesses to "struct route_list * rl", check first that rl is non-NULL
authorGert Doering <gert@greenie.muc.de>
Tue, 16 Aug 2011 18:05:13 +0000 (20:05 +0200)
committerDavid Sommerseth <davids@redhat.com>
Wed, 24 Aug 2011 12:24:56 +0000 (14:24 +0200)
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 <gert@greenie.muc.de>
Acked-By: David Sommerseth <davids@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
route.c
route.h

diff --git a/route.c b/route.c
index 4ffb6f51a1162fc91ecbed9c67fadf1e351f7495..f91edda0c4e03ca6f54b58deb74d614161f77406 100644 (file)
--- 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 f900d3e0ad8878a0306436d0e51c04b7a99810bf..995347889a087f6eb1128a74022c76c2805672ee 100644 (file)
--- 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