lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [bug #60569] lwip_gethostbyname(_r) does not handle IPv4/IP


From: Patrik Lantto
Subject: [lwip-devel] [bug #60569] lwip_gethostbyname(_r) does not handle IPv4/IPv6 correctly
Date: Mon, 10 May 2021 03:27:18 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.56

URL:
  <https://savannah.nongnu.org/bugs/?60569>

                 Summary: lwip_gethostbyname(_r) does not handle IPv4/IPv6
correctly
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: patriklantto
            Submitted on: Mon 10 May 2021 07:27:17 AM UTC
                Category: DNS
                Severity: 3 - Normal
              Item Group: Faulty Behaviour
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None
            lwIP version: git head

    _______________________________________________________

Details:

lwip_gethostbyname and lwip_gethostbyname_r are currently always setting the
h_addrtype field of struct hostent to AF_INET disregarding if the result is
IPv4 or IPv6. Moreover, the h_length field is set to sizeof (ip_addr_t)
instead of sizeof (struct in_addr) or sizeof (struct in6_addr) respectively.
An application that uses the h_length field to copy the adress would
potentially corrupt memory; the amount of corrupted bytes depends on whether
lwIP is compiled with IPv6 support or not.

Since h_addrtype is hardcoded to AF_INET, a quick solution (or an intermediate
step) is to use netconn_gethostbyname_addrtype instead of
netconn_gethostbyname, and specify NETCONN_DNS_IPV4 to ensure only an IPv4
address is returned, and set h_length to sizeof (struct in_addr). A long term
solution is to look at the address type and set the fields of hostent
(including h_addrtype and h_length dynamically).




    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?60569>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]