ptp: Ensure that not too much is read from or written to struct ifreq.ifr_name

This commit is contained in:
Sebastian Dröge 2015-06-08 12:02:39 +02:00
parent 0d96487879
commit c8d777feaa

View file

@ -253,16 +253,16 @@ setup_sockets (void)
probed_ifaces = g_new0 (gchar *, ifc.ifc_len + 1);
for (i = 0; i < ifc.ifc_len / sizeof (struct ifreq); i++) {
strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
strncpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name, IFNAMSIZ);
if (ioctl (g_socket_get_fd (socket_event), SIOCGIFFLAGS, &ifr) == 0) {
if ((ifr.ifr_flags & IFF_LOOPBACK))
continue;
probed_ifaces[idx] = g_strdup (ifc.ifc_req[i].ifr_name);
probed_ifaces[idx] = g_strndup (ifc.ifc_req[i].ifr_name, IFNAMSIZ);
idx++;
} else {
g_warning ("can't get flags of interface '%s'",
ifc.ifc_req[i].ifr_name);
probed_ifaces[idx] = g_strdup (ifc.ifc_req[i].ifr_name);
probed_ifaces[idx] = g_strndup (ifc.ifc_req[i].ifr_name, IFNAMSIZ);
idx++;
}
if (idx != 0)
@ -305,7 +305,7 @@ setup_sockets (void)
gchar **ptr = ifaces;
while (*ptr) {
strcpy (ifr.ifr_name, *ptr);
strncpy (ifr.ifr_name, *ptr, IFNAMSIZ);
if (ioctl (g_socket_get_fd (socket_event), SIOCGIFHWADDR, &ifr) == 0) {
clock_id_array[0] = ifr.ifr_hwaddr.sa_data[0];
clock_id_array[1] = ifr.ifr_hwaddr.sa_data[1];
@ -331,7 +331,7 @@ setup_sockets (void)
guint i;
for (i = 0; i < ifc.ifc_len / sizeof (struct ifreq); i++) {
strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
strncpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name, IFNAMSIZ);
if (ioctl (g_socket_get_fd (socket_event), SIOCGIFFLAGS, &ifr) == 0) {
if ((ifr.ifr_flags & IFF_LOOPBACK))
continue;