One of the InternetAddress constructors
https://github.com/dlang/phobos/blob/v2.078.0/std/socket.d#L1563
assumes that a succesful InternetHost.gethostbyname call results in at least one entry in addrList.
The implementation of InternetHost.populate, which fills addrList:
https://github.com/dlang/phobos/blob/v2.078.0/std/socket.d#L704-L716
has a case where addrList remains null.
This at least *looks* like a problem; either the addrList = null case in populate should never be reached, or the assumption in the InternetAddress constructor is invalid, right?
I came to look at this because I had code which tripped an out of range exception on https://github.com/dlang/phobos/blob/v2.078.0/std/socket.d#L1563 . In my case this may have been due to use of gethostbyname by a third party (non-D) library, which obviously didn't respect the phobos mutex around gethostbyname.
My workaround is currently to not use InternetAddress at all.
gethostbyname is deprecated in any case (=> https://issues.dlang.org/show_bug.cgi?id=15424), so maybe a rewrite or deprecation here is in order anyway?
Comment #1 by robert.schadek — 2024-12-01T16:32:07Z