[maint] alfred: Fix detection of own packets for IPv4 mode

Message ID 20181029170542.5406-1-sven@narfation.org (mailing list archive)
State Accepted, archived
Commit db842ed210d00345619e0ebc45a4d0d840e0b7e5
Delegated to: Simon Wunderlich
Headers
Series [maint] alfred: Fix detection of own packets for IPv4 mode |

Commit Message

Sven Eckelmann Oct. 29, 2018, 5:05 p.m. UTC
  The incoming packet address is checked for a match against the local
interface addresses to avoid processing its own packets. The IPv4
implementation used the same code but only initialized 4 of the 16 bytes of
the address in the recv function. The interface initialization code in
netsock_set_interfaces set all unused bytes to zero but recv_alfred_packet
was modified to use 12 random bytes from the stack.

Both functions must work the same way and first set the address bytes to
zero and overwrite the actual used bytes with the address bytes. Otherwise,
the result of netsock_set_interfaces for own packets is random in the IPv4
implementation.

Fixes: c7da798113a2 ("alfred: IPv4 multicast distribution support.")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Cc: Jonathan Haws <jhaws@sdl.usu.edu>
---
 recv.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Jonathan Haws Oct. 29, 2018, 5:55 p.m. UTC | #1
Tested By: Jonathan Haws <jhaws@sdl.usu.edu>

On Mon, 2018-10-29 at 18:05 +0100, Sven Eckelmann wrote:
> The incoming packet address is checked for a match against the local
> interface addresses to avoid processing its own packets. The IPv4
> implementation used the same code but only initialized 4 of the 16
> bytes of
> the address in the recv function. The interface initialization code
> in
> netsock_set_interfaces set all unused bytes to zero but
> recv_alfred_packet
> was modified to use 12 random bytes from the stack.
> 
> Both functions must work the same way and first set the address bytes
> to
> zero and overwrite the actual used bytes with the address bytes.
> Otherwise,
> the result of netsock_set_interfaces for own packets is random in the
> IPv4
> implementation.
> 
> Fixes: c7da798113a2 ("alfred: IPv4 multicast distribution support.")
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
> Cc: Jonathan Haws <jhaws@sdl.usu.edu>
> ---
>  recv.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/recv.c b/recv.c
> index 59d759c..5ff4bb5 100644
> --- a/recv.c
> +++ b/recv.c
> @@ -416,6 +416,7 @@ int recv_alfred_packet(struct globals *globals,
> struct interface *interface,
>  
>  	packet = (struct alfred_tlv *)buf;
>  
> +	memset(&alfred_source, 0, sizeof(alfred_source));
>  	if (globals->ipv4mode) {
>  		memcpy(&alfred_source, &source4.sin_addr,
> sizeof(source4.sin_addr));
>  	} else {
  

Patch

diff --git a/recv.c b/recv.c
index 59d759c..5ff4bb5 100644
--- a/recv.c
+++ b/recv.c
@@ -416,6 +416,7 @@  int recv_alfred_packet(struct globals *globals, struct interface *interface,
 
 	packet = (struct alfred_tlv *)buf;
 
+	memset(&alfred_source, 0, sizeof(alfred_source));
 	if (globals->ipv4mode) {
 		memcpy(&alfred_source, &source4.sin_addr, sizeof(source4.sin_addr));
 	} else {