On 1/1/21 11:22 AM, Oldřich Jedlička wrote:
pá 1. 1. 2021 v 11:02 odesílatel Oldřich Jedlička <oldium....@gmail.com> napsal:

Hi,

pá 1. 1. 2021 v 2:20 odesílatel Hauke Mehrtens <ha...@hauke-m.de> napsal:

ai_addr has different sizes for IPv4 and IPv6. Only copy the parts which
are actually used and not the full array, to not copy and uninitialized
memory.

This fixes a warning found with the address sanitizer.

Signed-off-by: Hauke Mehrtens <ha...@hauke-m.de>
---
....
  };
@@ -189,7 +192,9 @@ int uh_socket_bind(const char *host, const char *port, bool 
tls)

                 l->fd.fd = sock;
                 l->tls = tls;
-               l->addr = *(struct sockaddr_in6 *)p->ai_addr;
+               if (p->ai_addrlen < sizeof(l->addr))

I think that this sizeof takes the smallest part of the (anonymous)
union - sockaddr_in addr, not the whole union size. You either need to
name the union and sizeof the whole content, or manually select the
biggest entry for use in sizeof, which is addr6.

Also strict less-than doesn't look correct.

Yes you are right, I will send an update.
I changed this code multiple times and had this laying around for some time now.

Hauke

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to