icmp_interface_update() calls get_primarymac_netlink() but discards its
return value. That helper only writes the output buffer on success; on
failure (netlink error, or BATADV_ATTR_HARD_ADDRESS missing from the
BATADV_CMD_GET_MESH_INFO reply) it returns a negative errno and leaves the
buffer untouched. primary_mac is a zero-initialised static and this is the
only place that ever writes it, so a failed query leaves it as
00:00:00:00:00:00. And address which the receiver cannot use to send a
reply.

Propagate the failure out of icmp_interface_update() and abort the send.

Fixes: 4bd751eed4dc ("batctl: Implement non-routing batadv_icmp in userspace")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 icmp_helper.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/icmp_helper.c b/icmp_helper.c
index 65a2005..52ac22d 100644
--- a/icmp_helper.c
+++ b/icmp_helper.c
@@ -337,9 +337,7 @@ static int icmp_interface_update(struct state *state)
        /* remove old interfaces */
        icmp_interface_sweep();
 
-       get_primarymac_netlink(state, primary_mac);
-
-       return 0;
+       return get_primarymac_netlink(state, primary_mac);
 }
 
 static int icmp_interface_send(struct batadv_icmp_header *icmp_packet,
@@ -391,7 +389,9 @@ int icmp_interface_write(struct state *state,
        if (icmp_packet->msg_type != BATADV_ECHO_REQUEST)
                return -EINVAL;
 
-       icmp_interface_update(state);
+       ret = icmp_interface_update(state);
+       if (ret < 0)
+               return ret;
 
        if (list_empty(&interface_list))
                return -EFAULT;

-- 
2.47.3

Reply via email to