aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2017-12-14 13:48:12 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2017-12-14 14:26:55 +0100
commit4d407a18ca46f93d206e7c15042891ee6968ebae (patch)
treedaa4f7ad7b7cafefe6a09b0b6e360eba2b14d154
parentcb809ca72148da89ea8e9d826b33e98197f0bbe9 (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
-rw-r--r--lib/tun.c5
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");