Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when resolving address with std.socket.getAddress inside a Fiber #9762

Open
dlangBugzillaToGithub opened this issue Sep 15, 2018 · 0 comments
Labels
Arch:x86_64 Issues specific to x86_64 OS:Linux Issues specific to Linux Severity:Crash Severity:Major

Comments

@dlangBugzillaToGithub
Copy link

zorael reported this on 2018-09-15T00:10:06Z

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

Description

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
> [...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch:x86_64 Issues specific to x86_64 OS:Linux Issues specific to Linux Severity:Crash Severity:Major
Projects
None yet
Development

No branches or pull requests

3 participants