From 589e3aa54e805fa1a0061d8451c170b267967390 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 25 Jun 2018 07:51:21 -0600 Subject: [PATCH] net/udp: Fix a whole in the address lookup logic. --- net/udp/udp_finddev.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/net/udp/udp_finddev.c b/net/udp/udp_finddev.c index d47cb0b783..c5b147d297 100644 --- a/net/udp/udp_finddev.c +++ b/net/udp/udp_finddev.c @@ -165,7 +165,7 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn) * uninitialized and that the socket is, hence, not bound. */ - if (conn->u.ipv4.laddr == 0) + if (conn->u.ipv4.laddr == 0) /* INADDR_ANY */ { return NULL; } @@ -176,13 +176,23 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn) } } - /* Normal lookup using the remote address */ + /* There is no unique device associated with the unspecified + * address. + */ - else + else if (conn->u.ipv4.raddr != INADDR_ANY) { + /* Normal lookup using the verified remote address */ + return netdev_findby_ipv4addr(conn->u.ipv4.laddr, conn->u.ipv4.raddr); } + else + { + /* Not a suitable IPv4 unicast address for device lookup */ + + return NULL; + } } #endif @@ -215,13 +225,23 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn) } } - /* Normal lookup using the remote address */ + /* There is no unique device associated with the unspecified + * address. + */ - else + else if (!net_ipv6addr_cmp(conn->u.ipv6.raddr, g_ipv6_unspecaddr)) { + /* Normal lookup using the verified remote address */ + return netdev_findby_ipv6addr(conn->u.ipv6.laddr, conn->u.ipv6.raddr); } + else + { + /* Not a suitable IPv6 unicast address for device lookup */ + + return NULL; + } } #endif }