[Issue 19247] New: Segmentation fault when resolving address with std.socket.getAddress inside a Fiber

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Sep 15 00:10:06 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19247

          Issue ID: 19247
           Summary: Segmentation fault when resolving address with
                    std.socket.getAddress inside a Fiber
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: zorael at gmail.com

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
> [...]

--


More information about the Digitalmars-d-bugs mailing list