Skip to contentSkip to conversation

alfred: Avoid buffer overflow while querying ARP cache

PATCH In review Sven Eckelmann 3 participants 4 messages Jan 27, 2017 – Jan 30, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 alfred: Avoid buffer overflow while querying ARP cache

The arpreq.arp_dev is a limited buffer (16 bytes). Avoid that more bytes from the interface name are copied into this buffer by switching from strcpy to strncpy.

Fixes c7da798113a2 ("alfred: IPv4 multicast distribution support.")
---
 util.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
util.c +3 -1
index 84ab3af..ed83895 100644
@@ -92,7 +92,9 @@ int ipv4_arp_request(struct interface *interface, const alfred_addr *addr,
 	sin->sin_family = AF_INET;
 	sin->sin_addr.s_addr = addr->ipv4.s_addr;
 
-	strcpy(arpreq.arp_dev, interface->interface);
+	strncpy(arpreq.arp_dev, interface->interface, sizeof(arpreq.arp_dev));
+	arpreq.arp_dev[sizeof(arpreq.arp_dev) - 1] = '\0';
+
 	if (ioctl(interface->netsock, SIOCGARP, &arpreq) < 0)
 		return -1;
 
Signature · 1 line
2.11.0
#1 lore raw
Quoted 15 lines · Sven Eckelmann

The arpreq.arp_dev is a limited buffer (16 bytes). Avoid that more bytes from the interface name are copied into this buffer by switching from strcpy to strncpy.

Fixes c7da798113a2 ("alfred: IPv4 multicast distribution support.")
---
 util.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
util.c +0 -0
index 84ab3af..ed83895 100644

util.c int ipv4_arp_request(struct interface *interface, const alfred_addr *addr, · line 95

Quoted 5 lines
util.c +1 -1
@@ -92,7 +92,9 @@ int ipv4_arp_request(struct interface *interface, const alfred_addr *addr,
 	sin->sin_family = AF_INET;
 	sin->sin_addr.s_addr = addr->ipv4.s_addr;
 
-	strcpy(arpreq.arp_dev, interface->interface);
+	strncpy(arpreq.arp_dev, interface->interface, sizeof(arpreq.arp_dev));

arpreq is already set to 0 few lines above. why not simpling "sizeof(arpreq.arp_dev) - 1" as last argument for the strncpy() and avoid the line below?

Or is this required for consistency with the rest of the code?

Cheers,

Signature · 1 line
Antonio Quartulli
#2 lore raw

On Freitag, 27. Januar 2017 22:34:22 CET Antonio Quartulli wrote:
[...]

Quoted 5 lines

arpreq is already set to 0 few lines above. why not simpling "sizeof(arpreq.arp_dev) - 1" as last argument for the strncpy() and avoid the line below?

Or is this required for consistency with the rest of the code?

It is done for consistency.

Kind regards,
Sven

#3 lore raw
In reply to Sven Eckelmann
Quoted 6 lines · CET Sven Eckelmann

The arpreq.arp_dev is a limited buffer (16 bytes). Avoid that more bytes from the interface name are copied into this buffer by switching from strcpy to strncpy.

Fixes c7da798113a2 ("alfred: IPv4 multicast distribution support.")

Committed in revision 26ef92b.

Thank you,
Simon