Issue 19247 - Segmentation fault when resolving address with std.socket.getAddress inside a Fiber
Summary: Segmentation fault when resolving address with std.socket.getAddress inside a...
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-15 00:10 UTC by JR
Modified: 2024-12-01 16:34 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description JR 2018-09-15 00:10:06 UTC
Manjaro/Arch x86_64. dmd 2.082, ldc v1.11 from repositories.

Resolving an invalid address with no dots, such as "asdf", causes a segmentation fault. Resolving a nonexistent address throws an exception, as it should, and valid addresses resolve fine.

Noteworthy is that it started after I moved the resolving into a function run as a Generator Fiber. Calls to getAddress outside of it seem to work fine. Unsure if that's relevant.

Tested on two machines running Linux, with dmd and ldc. On a Windows machine however it properly threw a SocketOSException: getaddrinfo error: No such host is known.

Reduced example (31 lines) is at the resolveseg branch of https://github.com/zorael/kameloso.

> $ git clone https://github.com/zorael/kameloso.git -b resolveseg
> $ cd kameloso
> $ ./tester
> 0x00007ffff7a583a8 in __res_context_hostalias () from /usr/lib/libresolv.so.2

Manually, invalid address:
> $ gdb --batch -ex run --args kameloso wefpok
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library "/usr/lib/libthread_db.so.1".
> Attempting to resolve wefpok
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x00007ffff7a583a8 in __res_context_hostalias () from /usr/lib/libresolv.so.2

Manually, valid address:
> $ gdb --batch -ex run --args kameloso dlang.org
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library "/usr/lib/libthread_db.so.1".
> Attempting to resolve dlang.org
> Success
> [Inferior 1 (process 15589) exited normally]

Random changes to the source makes it segfault in getenv in libc.so.6 instead. For instance, version/comment out the foreach in resolveFiber in connection.d.

> (gdb) bt
> #0  0x00007ffff7683b1d in getenv () from /usr/lib/libc.so.6
> #1  0x00007ffff74cd3ae in __res_context_hostalias () from /usr/lib/libresolv.so.2
> #2  0x00007ffff74cd7bd in __res_context_search () from /usr/lib/libresolv.so.2
> #3  0x00007ffff747ce6d in _nss_dns_gethostbyname4_r () from /usr/lib/libnss_dns.so.2
> #4  0x00007ffff772efa2 in gaih_inet.constprop () from /usr/lib/libc.so.6
> #5  0x00007ffff772ffc8 in getaddrinfo () from /usr/lib/libc.so.6
> #6  0x00007ffff7ccffe7 in _D3std6socket18getAddressInfoImplFMAxaMQePS4core3sys5posix5netdb8addrinfoZASQCwQCv11AddressInfo () from /usr/lib/libphobos2.so.0.82
> [...]
Comment 1 dlangBugzillaToGithub 2024-12-01 16:34:09 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9762

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB