<div dir="ltr">Hi,<div><br></div><div>I have joined this mailing list because I have a difficult bug which seems to relate to a c-ares function call. </div><div><br></div><div>The program I am developing reads lines from a file which is a list of domain names. It performs asynchronous dns and then downloads the landing pages with an epoll based event loop. The program runs well for thousands of iterations and then bombs out with a *** buffer overflow detected ***: terminated error. The following backtrace points the finger of blame at a call to ares_fd:</div><div><br></div><div>Program received signal SIGABRT, Aborted.<br>__pthread_kill_implementation (no_tid=0, signo=6, threadid=140737351407424) at pthread_kill.c:44<br>44  pthread_kill.c: No such file or directory.<br>(gdb) bt<br>#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140737351407424) at pthread_kill.c:44<br>#1  __pthread_kill_internal (signo=6, threadid=140737351407424) at pthread_kill.c:80<br>#2  __GI___pthread_kill (threadid=140737351407424, signo=signo@entry=6) at pthread_kill.c:91<br>#3  0x00007ffff7dae476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26<br>#4  0x00007ffff7d947b7 in __GI_abort () at abort.c:79<br>#5  0x00007ffff7df55e6 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff7f46ef4 "*** %s ***: terminated\n") at ../sysdeps/posix/libc_fatal.c:155<br>#6  0x00007ffff7ea122a in __GI___fortify_fail (msg=msg@entry=0x7ffff7f46e9a "buffer overflow detected") at fortify_fail.c:26<br>#7  0x00007ffff7e9fb46 in __GI___chk_fail () at chk_fail.c:28<br>#8  0x00007ffff7ea116b in __fdelt_chk (d=<optimised out>) at fdelt_chk.c:25<br>#9  0x00007ffff7f9699a in ares_fds () from /usr/local/lib/libcares.so.2<br>#10 0x000055555555682d in wait_ares (channel=0x555556bb32a0) at epoll_recv_with_async_dns.c:80<br>#11 0x000055555555772e in main (argc=2, argv=0x7fffffffe0a8) at epoll_recv_with_async_dns.c:299<br></div><div><br></div><div>The offending line of code is:</div><div><br></div><div>nfds = ares_fds(channel, &read_fds, &write_fds);<br></div><div><br></div><div>I don't understand how this is a buffer overflow as the function call only uses locally initialised variables. Here is the full function:</div><div><br></div><div>static void wait_ares(ares_channel channel)<br>{<br>    struct timeval *tvp, tv;<br>    fd_set read_fds, write_fds;<br>    int nfds;<br><br>    FD_ZERO(&read_fds);<br>    FD_ZERO(&write_fds);<br>    nfds = ares_fds(channel, &read_fds, &write_fds);<br><br>    if (nfds > 0) {<br>    tvp = ares_timeout(channel, NULL, &tv);<br>    select(nfds, &read_fds, &write_fds, NULL, tvp);<br>    ares_process(channel, &read_fds, &write_fds);<br>    }<br>}<br></div><div><br></div><div>Just in case I haven't provided enough information a full code listing can be downloaded from <a href="https://github.com/JamesRead5737/epoll-and-c-ares-crawler">https://github.com/JamesRead5737/epoll-and-c-ares-crawler</a></div></div>