From: Florian Forster Date: Wed, 27 May 2009 07:27:44 +0000 (+0200) Subject: src/linux/device.c: Fix segfault when running without `--net'. X-Git-Tag: release-1.0.10~59 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=6b415a1a7f5bad2fff7b133ef2a2febccb96d6e5;p=tinc src/linux/device.c: Fix segfault when running without `--net'. 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 --- diff --git a/src/linux/device.c b/src/linux/device.c index 2e447556..4e9591c2 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