Clean up ifreq_set_ifname() and use it from bsd_open_tun() too
Currently, if we set a name with --interface which is too long to fit in
ifr->ifr_name, it gets silently truncated with strncpy(). This in itself
is not immediately broken, although the FreeBSD build does complain:
tun.c:262:17: warning: 'strncpy' output may be truncated copying 15 bytes from a string of length 74 [-Wstringop-truncation]
262 | strncpy(ifr.ifr_name, tun_name + 5, sizeof(ifr.ifr_name) - 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It's not *immediately* broken, and there are no string overflows; the NUL
termination is there anyway. But it *is* broken eventually, because we'll
spawn vpnc-script with the *originally* intended name, and it won't find
the device with that name.
So fix it up to check the length and then return an error if the requested
name is too long, and just use memcpy() to put the string into ifr_name,
which was pre-zeroed anyway.
Signed-off-by: David Woodhouse <email address hidden>