]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
sitnl: harden strncpy() by forcing arguments to have the same length
authorAntonio Quartulli <antonio@openvpn.net>
Mon, 5 Aug 2019 09:25:24 +0000 (11:25 +0200)
committerGert Doering <gert@greenie.muc.de>
Thu, 15 Aug 2019 18:21:57 +0000 (20:21 +0200)
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 <antonio@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
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 <gert@greenie.muc.de>
src/openvpn/networking_sitnl.c
src/openvpn/route.h

index 05cc0acf944a8be266144b41c315fd193bf9f9d8..21563905072eda085c2974e66dca384cc7ea5d3d 100644 (file)
@@ -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;
 
index 31d38e36a73737bb35df072d7bda274b2fb1ba5d..2e68091cdfd161c1ec1ef66f14f0f3a8ab7e2db6 100644 (file)
@@ -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 */