diff options
authorPau Espin Pedrol <pespin@sysmocom.de>2017-12-14 13:48:12 +0100
committerHarald Welte <laforge@gnumonks.org>2017-12-14 14:49:12 +0000
commit02e21af657abff93319bffe1c7c0272245a6c0d1 (patch)
parentbffc3f901275a8102c3f94735f48f0681458afc0 (diff)
tun.c: tun_addaddr: Fix segfault and wrong usage of tun_nlattr
First of all, dstaddr can be NULL, avoid copying it in that case. Second, we want to copy the addr data, not the pointer. I tested it and the IP was not added (not shown in ip addr) until I copied the content instead of the address. Change-Id: I8da637b155f0e913cab6c5b0dde355c9f33375b5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/tun.c b/lib/tun.c
index d8e4b62..3081575 100644
--- a/lib/tun.c
+++ b/lib/tun.c
@@ -333,8 +333,9 @@ int tun_addaddr(struct tun_t *this,
return -1;
- tun_nlattr(&req.n, sizeof(req), IFA_ADDRESS, addr, sizeof(addr));
- tun_nlattr(&req.n, sizeof(req), IFA_LOCAL, dstaddr, sizeof(dstaddr));
+ tun_nlattr(&req.n, sizeof(req), IFA_ADDRESS, addr, sizeof(*addr));
+ if (dstaddr)
+ tun_nlattr(&req.n, sizeof(req), IFA_LOCAL, dstaddr, sizeof(*dstaddr));
if ((fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) {
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");