From: Antonio Quartulli Date: Mon, 5 Aug 2019 09:25:24 +0000 (+0200) Subject: sitnl: harden strncpy() by forcing arguments to have the same length X-Git-Tag: v2.5_beta1~290 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a05f860af386cd135ee1aacb0d5eccc49c466bb;p=thirdparty%2Fopenvpn.git sitnl: harden strncpy() by forcing arguments to have the same length At the moment a strcpy() (without length check!) is performed between a string long IFNAMSIZ bytes and one of 16 bytes. This is ok right now because IFNAMSIZ is defined as 16, however this bit is not under our control and may change in he future without us being warned. For this reason, force both strings to use IFNAMSIZ as size and, since this constant may not exist on every platform, ensure it is always defined. Signed-off-by: Antonio Quartulli Acked-by: Gert Doering Message-Id: <20190805092529.9467-2-a@unstable.cc> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18722.html Signed-off-by: Gert Doering --- diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index 05cc0acf9..215639050 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -493,7 +493,7 @@ sitnl_route_best_gw(sa_family_t af_family, const inet_address_t *dst, /* save result in output variables */ memcpy(best_gw, &res.gw, res.addr_size); - strcpy(best_iface, res.iface); + strncpy(best_iface, res.iface, IFNAMSIZ); err: return ret; diff --git a/src/openvpn/route.h b/src/openvpn/route.h index 31d38e36a..2e68091cd 100644 --- a/src/openvpn/route.h +++ b/src/openvpn/route.h @@ -184,7 +184,11 @@ struct route_ipv6_gateway_info { #ifdef _WIN32 DWORD adapter_index; /* interface or ~0 if undefined */ #else - char iface[16]; /* interface name (null terminated), may be empty */ + /* non linux platform don't have this constant defined */ +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif + char iface[IFNAMSIZ]; /* interface name (null terminated), may be empty */ #endif /* gateway interface hardware address */