urnathan / libcody

Compiler/BuildSystem Interface Library
Apache License 2.0
24 stars 6 forks source link

libcody: Avoid a crash in getaddrinfo() on some BSD/BSD-derived versi… #28

Closed iains closed 2 years ago

iains commented 2 years ago

…ons.

In some cases, on some older BSD versions (and macOS versions based on that code) getaddrinfo() crashes when given ai_flags = AI_NUMERICSERV together with either a nullptr or the literal string "0" for the servname parameter.

In the case of OpenInet6() it seems that there is no useful case when we could have an empty name (and we ignore the port number passed when calling getaddrinfo).

The change here diagnoses a missing server name early, and then calls the getaddrinfo() with ai_flags = 0 and a nullptr for servname.

We do check the validity of the port number in the next section of the code that carries out the connect.

When applied to the GCC implementation of P1184, this fixes the remaining fails on the affected macOS versions.

iains commented 2 years ago

note that I have not tested this widely yet - wanted to float the approach first.