[PATCH] src/linux/device.c: Fix segfault when running without `--net'.

Florian Forster octo at verplant.org
Wed May 27 09:27:44 CEST 2009


If running without `--net', the (global) variable `netname' is NULL. This
creates a segmentation fault because this NULL-pointer is passed to strdup:

 Program terminated with signal 11, Segmentation fault.
 #0  0xb7d30463 in strlen () from /lib/tls/i686/cmov/libc.so.6
 (gdb) bt
 #0  0xb7d30463 in strlen () from /lib/tls/i686/cmov/libc.so.6
 #1  0xb7d30175 in strdup () from /lib/tls/i686/cmov/libc.so.6
 #2  0x0805bf47 in xstrdup (s=0x0) at xmalloc.c:118  <---
 #3  0x0805be33 in setup_device () at device.c:66
 #4  0x0805072e in setup_myself () at net_setup.c:432
 #5  0x08050db2 in setup_network () at net_setup.c:536
 #6  0x0805b27f in main (argc=Cannot access memory at address 0x0) at tincd.c:580

This patch fixes this by checking `netname' in `setup_device'. An alternative
would be to check for NULL-pointers in `xstrdup' and return NULL in this case.

Signed-off-by: Florian Forster <octo at verplant.org>
---
 src/linux/device.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/linux/device.c b/src/linux/device.c
index 2e44755..4e9591c 100644
--- a/src/linux/device.c
+++ b/src/linux/device.c
@@ -63,7 +63,8 @@ bool setup_device(void)
 
 	if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
 #ifdef HAVE_LINUX_IF_TUN_H
-		iface = xstrdup(netname);
+		if (netname != NULL)
+			iface = xstrdup(netname);
 #else
 		iface = xstrdup(rindex(device, '/') ? rindex(device, '/') + 1 : device);
 #endif
-- 
1.5.6.5



More information about the tinc-devel mailing list