aio-libs / aiodns

Simple DNS resolver for asyncio
https://pypi.python.org/pypi/aiodns
MIT License
532 stars 69 forks source link

.onion pseudo TLD leads to segmentation fault #70

Closed 0x3c3e closed 5 years ago

0x3c3e commented 5 years ago

I have stumbled with an issue, pseudo .onion TLD leads to segmentation fault. Code is simple as:

import asyncio
import aiodns

loop = asyncio.get_event_loop()
resolver = aiodns.DNSResolver(loop=loop)

async def query(name, query_type):
    return await resolver.query(name, query_type)

coro = query('something.onion', 'NS') # actually any DNS record (e.g. A, CNAME, MX)
result = loop.run_until_complete(coro)

Let me know if it's expected behaviour.

saghul commented 5 years ago

A segmentation fault should never be expected behavior :-O Do you have a backtrace? I'll try to look into this soon.

0x3c3e commented 5 years ago

Hi again @saghul, here it is:

faulthandler.enable()

loop = asyncio.get_event_loop() resolver = aiodns.DNSResolver(loop=loop)

async def query(name, query_type): return await resolver.query(name, query_type)

coro = query('something.onion', 'NS') # actually any DNS record (e.g. A, CNAME, MX) result = loop.run_until_complete(coro)

* _segmentation fault:_

Fatal Python error: Segmentation fault

Current thread 0x{addr} (most recent call first): File "/home/{user}/.pyenv/versions/{env}/lib/python3.7/site-packages/pycares/init.py", line 519 in _do_query File "/home/{user}/.pyenv/versions/{env}/lib/python3.7/site-packages/pycares/init.py", line 505 in query File "/home/{user}/.pyenv/versions/{env}/lib/python3.7/site-packages/aiodns/init.py", line 79 in query File "test.py", line 11 in query File "/home/{user}/.pyenv/versions/3.7.4/lib/python3.7/asyncio/events.py", line 88 in _run File "/home/{user}/.pyenv/versions/3.7.4/lib/python3.7/asyncio/base_events.py", line 1771 in _run_once File "/home/{user}/.pyenv/versions/3.7.4/lib/python3.7/asyncio/base_events.py", line 534 in run_forever File "/home/{user}/.pyenv/versions/3.7.4/lib/python3.7/asyncio/base_events.py", line 566 in run_until_complete File "test.py", line 14 in Segmentation fault (core dumped)

saghul commented 5 years ago

This should fix it: https://github.com/saghul/pycares/pull/101