[PATCH uhttpd 2/3] listen: Copy only parts of ai_addr

Hauke Mehrtens hauke at hauke-m.de
Fri Jan 1 10:58:42 EST 2021


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.pro at gmail.com> napsal:
>>
>> Hi,
>>
>> pá 1. 1. 2021 v 2:20 odesílatel Hauke Mehrtens <hauke at 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 <hauke at 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



More information about the openwrt-devel mailing list