Skip to contentSkip to conversation

Fix NULL-pointer crash in route_list_add_vpn_gateway().

PATCH In review Gert Doering 2 participants 3 messages May 3, 2013 – May 18, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix NULL-pointer crash in route_list_add_vpn_gateway().

Add ASSERT() check to route_list_add_vpn_gateway() to ensure that *rl is valid (and if not, crash with a somewhat more meaningful message than "segmentation violation"). For the actual bugfix, change init code to always allocate a "struct route_list" for IPv4, even if no --route options have been seen in the config.

Fix trac#281 and trac#258.

---
 src/openvpn/init.c  | 7 ++++---
 src/openvpn/route.c | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)
src/openvpn/init.c +4 -3
index 98f5489..694d086 100644
@@ -1145,13 +1145,14 @@ do_init_traffic_shaper (struct context *c)
 }
 
 /*
- * Allocate a route list structure if at least one
- * --route option was specified.
+ * Allocate route list structures for IPv4 and IPv6
+ * (we do this for IPv4 even if no --route option has been seen, as other
+ * parts of OpenVPN might want to fill the route-list with info, e.g. DHCP)
  */
 static void
 do_alloc_route_list (struct context *c)
 {
-  if (c->options.routes && !c->c1.route_list)
+  if (!c->c1.route_list)
     c->c1.route_list = new_route_list (c->options.max_routes, &c->gc);
   if (c->options.routes_ipv6 && !c->c1.route_ipv6_list)
     c->c1.route_ipv6_list = new_route_ipv6_list (c->options.max_routes, &c->gc);
src/openvpn/route.c +1 -0
index f5b5efa..72ecbaf 100644
@@ -503,6 +503,7 @@ route_list_add_vpn_gateway (struct route_list *rl,
 			    struct env_set *es,
 			    const in_addr_t addr)
 {
+  ASSERT(rl);
   rl->spec.remote_endpoint = addr;
   rl->spec.flags |= RTSA_REMOTE_ENDPOINT;
   setenv_route_addr (es, "vpn_gateway", rl->spec.remote_endpoint, -1);
Signature · 1 line
1.8.1.5
#1 lore raw
Quoted 9 lines · Gert Doering

Add ASSERT() check to route_list_add_vpn_gateway() to ensure that *rl is valid (and if not, crash with a somewhat more meaningful message than "segmentation violation"). For the actual bugfix, change init code to always allocate a "struct route_list" for IPv4, even if no --route options have been seen in the config.

Fix trac#281 and trac#258.

ACK to the fix.

As briefly discussed online, in the long-term the route_list_add_vpn_gateway() call in forward.c should probably be moved to a better location; it sounds like that's already in the works for a future changeset (and not required to fix this crash.)

--
Josh Cepek

#2 lore raw
In reply to Gert Doering

The patch has been applied to the master and release/2.3 branches.

commit eb95f367348f4c2aae301cfa7c3adc8e0f2e711e (master) commit 4203296fb9166c672e55586490e5bf237910ec56 (release/2.3)

Author: Gert Doering
Date:   Fri May 3 21:13:24 2013 +0200
     Fix NULL-pointer crash in route_list_add_vpn_gateway().

     Signed-off-by: Gert Doering <[email protected]...>
     Acked-by: Josh Cepek <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/7581

--
kind regards,

Gert Doering