diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-12-14 13:48:12 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-12-14 14:49:12 +0000 |
commit | 02e21af657abff93319bffe1c7c0272245a6c0d1 (patch) | |
tree | 5cff3f755fb5d2a4cb562be831a9d7bed5db0d06 /lib | |
parent | bffc3f901275a8102c3f94735f48f0681458afc0 (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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tun.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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"); |