273 Commits

Author SHA1 Message Date
Azat Khuzhin
00313c5050 evdns: evdns_base_free(): fix UAF of evdns_base with @fail_requests
If you call evdns_base_free() with @fail_requests == 1, then it will defer
callback with DNS_ERR_SHUTDOWN, but that callback (internal) uses
data->evdns_base, but we already freed that evdns base, so we can't do
this, fix this by checking @result to DNS_ERR_SHUTDOWN.

Fixes: regress dns/client_fail_requests_getaddrinfo
Fixes: #269
2015-11-25 13:09:02 +03:00
Azat Khuzhin
14f84bbdc7 evdns: evdns_base_free(): free requests before namservers
Otherwise we will trigger next UAF:
$ valgrind --vgdb-error=1 regress --no-fork +dns/client_fail_requests
==24733== Memcheck, a memory error detector
==24733== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==24733== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==24733== Command: regress --no-fork +dns/client_fail_requests
==24733==
==24733==
==24733== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==24733==   /path/to/gdb regress
==24733== and then give GDB the following command
==24733==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=24733
==24733== --pid is optional if only one valgrind process is running
==24733==
dns/client_fail_requests: ==24733== Invalid read of size 4
==24733==    at 0x4C3352: request_finished (evdns.c:662)
==24733==    by 0x4CC8B7: evdns_base_free_and_unlock (evdns.c:4048)
==24733==    by 0x4CCAFD: evdns_base_free (evdns.c:4088)
==24733==    by 0x458E95: dns_client_fail_requests_test (regress_dns.c:2039)
==24733==    by 0x48EA5D: testcase_run_bare_ (tinytest.c:105)
==24733==    by 0x48ED3F: testcase_run_one (tinytest.c:252)
==24733==    by 0x48F67E: tinytest_main (tinytest.c:434)
==24733==    by 0x47C0DA: main (regress_main.c:461)
==24733==  Address 0x61e6f70 is 448 bytes inside a block of size 456 free'd
==24733==    at 0x4C29EAB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24733==    by 0x4A8F4D: event_mm_free_ (event.c:3512)
==24733==    by 0x4CC7A1: evdns_nameserver_free (evdns.c:4021)
==24733==    by 0x4CC7DC: evdns_base_free_and_unlock (evdns.c:4037)
==24733==    by 0x4CCAFD: evdns_base_free (evdns.c:4088)
==24733==    by 0x458E95: dns_client_fail_requests_test (regress_dns.c:2039)
==24733==    by 0x48EA5D: testcase_run_bare_ (tinytest.c:105)
==24733==    by 0x48ED3F: testcase_run_one (tinytest.c:252)
==24733==    by 0x48F67E: tinytest_main (tinytest.c:434)
==24733==    by 0x47C0DA: main (regress_main.c:461)
==24733==  Block was alloc'd at
==24733==    at 0x4C28C4F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24733==    by 0x4A8D5A: event_mm_malloc_ (event.c:3437)
==24733==    by 0x4C8B96: evdns_nameserver_add_impl_ (evdns.c:2505)
==24733==    by 0x4C916D: evdns_base_nameserver_ip_add (evdns.c:2629)
==24733==    by 0x458DA3: dns_client_fail_requests_test (regress_dns.c:2031)
==24733==    by 0x48EA5D: testcase_run_bare_ (tinytest.c:105)
==24733==    by 0x48ED3F: testcase_run_one (tinytest.c:252)
==24733==    by 0x48F67E: tinytest_main (tinytest.c:434)
==24733==    by 0x47C0DA: main (regress_main.c:461)
==24733==
==24733== (action on error) vgdb me ...

Fixes: regress dns/client_fail_requests
Fixes: #269
2015-11-25 13:09:02 +03:00
Azat Khuzhin
9c238deb76 evdns: fix randomize-case by make case-insensitive as required
Interesting that this wasn't found by regression tests since they respond with
that SoME-rAndDom-CaSe domains, and no case-insensitive mode is required during
comparing response from the server and request.

Fixes #288
Covered-by: regress dns/search_lower
2015-10-09 01:13:53 +03:00
Azat Khuzhin
0c615f4ef3 evnds: inline TEST_NAME macro to make debuggin easier 2015-10-09 00:03:47 +03:00
Nick Mathewson
4472ec68e6 Merge pull request #212 from xbao/master
changed strtotimeval signature to avoid conflict with Android NDK sys/time.h header (#211)
2015-02-03 15:57:31 -05:00
Nick Mathewson
537177d315 New function to get address for nameserver. 2015-02-02 13:57:22 -05:00
Xiao Bao Clark
bdbc823f7e changed strtotimeval signature as per #211 2015-01-28 17:17:02 +11:00
Thomas Bernard
8afbdbc470 Fix mixed declarations and code (forbidden by ISO C90) 2014-12-08 10:21:00 +01:00
Azat Khuzhin
61262a0f08 evdns: avoid read-after-free in evdns_request_timeout_callback()
In evdns_request_timeout_callback() in case we a giving up, we call
request_finished() which will free() req structure, however we ns from
it to fail it, so save pointer to ns to call nameserver_failed() on
them.

Founded with valgrind:
$ valgrind regress dns/retry
==10497== Memcheck, a memory error detector
==10497== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==10497== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==10497== Command: regress dns/retry
==10497==
dns/retry: [forking] ==10498== Invalid read of size 8
==10498==    at 0x4C309D: evdns_request_timeout_callback (evdns.c:2179)
==10498==    by 0x49EA95: event_process_active_single_queue (event.c:1576)
==10498==    by 0x49EFDD: event_process_active (event.c:1668)
==10498==    by 0x49F6DD: event_base_loop (event.c:1891)
==10498==    by 0x49F063: event_base_dispatch (event.c:1702)
==10498==    by 0x44C7F1: dns_retry_test_impl (regress_dns.c:724)
==10498==    by 0x44CF60: dns_retry_test (regress_dns.c:749)
==10498==    by 0x48A8A1: testcase_run_bare_ (tinytest.c:105)
==10498==    by 0x48A94E: testcase_run_forked_ (tinytest.c:189)
==10498==    by 0x48AB73: testcase_run_one (tinytest.c:247)
==10498==    by 0x48B4C2: tinytest_main (tinytest.c:434)
==10498==    by 0x477FC7: main (regress_main.c:459)
==10498==  Address 0x6176ef8 is 40 bytes inside a block of size 342 free'd
==10498==    at 0x4C29E90: free (vg_replace_malloc.c:473)
==10498==    by 0x4A4411: event_mm_free_ (event.c:3443)
==10498==    by 0x4BE8C5: request_finished (evdns.c:702)
==10498==    by 0x4C3098: evdns_request_timeout_callback (evdns.c:2178)
==10498==    by 0x49EA95: event_process_active_single_queue (event.c:1576)
==10498==    by 0x49EFDD: event_process_active (event.c:1668)
==10498==    by 0x49F6DD: event_base_loop (event.c:1891)
==10498==    by 0x49F063: event_base_dispatch (event.c:1702)
==10498==    by 0x44C7F1: dns_retry_test_impl (regress_dns.c:724)
==10498==    by 0x44CF60: dns_retry_test (regress_dns.c:749)
==10498==    by 0x48A8A1: testcase_run_bare_ (tinytest.c:105)
==10498==    by 0x48A94E: testcase_run_forked_ (tinytest.c:189)
==10498==
==10498==
==10498== HEAP SUMMARY:
==10498==     in use at exit: 0 bytes in 0 blocks
==10498==   total heap usage: 83 allocs, 83 frees, 10,020 bytes allocated
==10498==
==10498== All heap blocks were freed -- no leaks are possible
==10498==
==10498== For counts of detected and suppressed errors, rerun with: -v
==10498== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
OK
1 tests ok.  (0 skipped)
==10497==
==10497== HEAP SUMMARY:
==10497==     in use at exit: 0 bytes in 0 blocks
==10497==   total heap usage: 3 allocs, 3 frees, 96 bytes allocated
==10497==
==10497== All heap blocks were freed -- no leaks are possible
==10497==
==10497== For counts of detected and suppressed errors, rerun with: -v
==10497== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Bug was introduced in 97c750d6602517f22a1100f16592b421c38f2a45 ("evdns:
fail ns after we are failing/retrasmitting request").
2014-11-12 20:20:11 +03:00
Azat Khuzhin
97c750d660 evdns: fail ns after we are failing/retrasmitting request
In case we are failing request (evdns_request_timeout_callback()), we
delete timeout_event in request_finished(), while just before calling
request_finished() (for failing request) there was a call to
nameserver_failed(), that add event for timeout_event, IOW we must fail
ns after request because otherwise we will not have timeout_event
actived, and we will waiting forever.

Before this patch the dns/retry_disable_when_inactive will wait forever,
after - OK.
2014-09-30 01:40:44 +04:00
Azat Khuzhin
74d0eee89b evdns: fix EVDNS_BASE_DISABLE_WHEN_INACTIVE in case retransmit/retry 2014-09-30 01:39:51 +04:00
Nick Mathewson
c8c7fa3a16 Merge pull request #119 from ldx/winhosts
Fix hosts file use on Windows.
2014-09-18 11:41:18 -04:00
Nick Mathewson
a7d5dabf96 Merge pull request #129 from azat/disable-probing-with-disable-when-inactive-v2
evdns: disable probing with EVDNS_BASE_DISABLE_WHEN_INACTIVE
2014-09-18 11:24:56 -04:00
ufo2243
3a4d249c9d [Bugfix] fix grammer error 2014-09-03 10:55:27 +08:00
Nick Mathewson
6a53d15383 Correctly handle allocation failures in evdns_getaddrinfo
Kuldeep Gupta appears to have used some kind of automated tool to
find this and generate a patch for half the issue as #149.
2014-08-29 15:26:56 -04:00
Azat Khuzhin
d83b3371e9 evdns: we don't need to add retry timer in transmit_to it will be done on fail 2014-04-10 19:46:11 +04:00
Azat Khuzhin
610410b586 evdns: disable probing with EVDNS_BASE_DISABLE_WHEN_INACTIVE
When user install EVDNS_BASE_DISABLE_WHEN_INACTIVE flag for evdns base,
we must remove the timer that is used for probing, if current dns server
failed, otherwise it won't break the loop.
2014-04-09 19:02:39 +04:00
Nick Mathewson
b163fdaad1 Merge remote-tracking branch 'origin/patches-2.0' 2014-03-26 11:10:16 -04:00
Nick Mathewson
e8fe749dba Fix a crash in evdns related to shutting down evdns
(Improved version to deal correctly with probe requests)

Patch from YASUOKA Masahiko; fix for libevent github issue #113.
2014-03-26 11:09:34 -04:00
Nick Mathewson
86665a582d Merge remote-tracking branch 'origin/patches-2.0' 2014-03-21 14:09:54 -04:00
Nick Mathewson
9f39c88756 Fix a crash in evdns related to shutting down evdns
Patch from YASUOKA Masahiko; fix for libevent github issue #113.
2014-03-21 14:08:17 -04:00
Vilmos Nebehaj
d0dc861b88 Don't truncate hosts file path on Windows.
Since evutil_snprintf() (actually evutil_vsnprintf() called by it) will
make sure the buffer is null-terminated by placing a null byte at
len_out - 1, we need to pass the full length of the buffer; otherwise
the path will end in "\\host" instead of "\\hosts".
2014-03-21 14:38:11 +01:00
Vilmos Nebehaj
a0b247cdc0 Load hosts file on Windows.
Hosts files are not loaded in evdns_base_config_windows_nameservers() if
load_nameservers_with_getnetworkparams() succeeds on Windows. Parse and
load it first before setting up nameservers.
2014-03-21 14:36:15 +01:00
Nick Mathewson
254c04ec4b Fix needless bufferevent includes in evdns.c 2013-12-24 15:01:34 -05:00
Antony Antony
62f596b7f4 fix for ServFail from RIPE Atlas release 2013-12-24 14:03:46 -05:00
Joakim Soderberg
e6b2a26755 Fix non-C89 variable declaration.
Microsofts C compiler does not support the C99 standard, so variables has
to be declared at the start of a scope.
2013-12-09 16:54:57 +01:00
Nick Mathewson
45eba6ffd5 Rename flush_outdated_host_addresses to clear_host_addresses
"flush" can imply writing something out to a file or connection before
clearing it; "clear" always means "remove".  It's also potentially
misleading to say "outdated" here, since the function removes _all_
addresses regardless, not just certain outdated ones.

Also, don't free the lock in this function.  Also reindent the function.
2013-12-06 10:50:17 -05:00
Kuldeep Gupta
954d2f94c0 bug fix for issues #293 evdns_base_load_hosts doesn't remove outdated adresses
As mentioned at https://sourceforge.net/p/levent/bugs/293/
 created a small function "evdns_base_flush_outdated_host_addresses" which removes all the previous requests of hosts , if user wants to clean up the list of hosts can call and use this function. 
Requires function declaration to be added in include/event2/dns.h
 Adding it in another patch for the same bug.
2013-12-06 16:53:16 +05:30
Greg Hazel
363388a043 restore the comment 2013-05-29 14:19:14 -07:00
Azat Khuzhin
f8d7df8591 Fix SEGFAULT after evdns_base_resume if no nameservers installed.
If there is no nameservers installed, using
evdns_base_nameserver_ip_add(), than evdns_base_resume() will SEGFAULT,
because of NULL dereference in evdns_requests_pump_waiting_queue()

Conflicts:
	evdns.c
2013-05-29 14:05:17 -07:00
Nick Mathewson
e1766a1b6d Actually use the log facility for reporting evdns problems.
Fixes issue #63.  Also refactors the evdns logging and log backend a
bit, so that it wastes a little less code.
2013-05-29 16:26:50 -04:00
Azat Khuzhin
14971a833c Fix SEGFAULT after evdns_base_resume if no nameservers installed.
If there is no nameservers installed, using
evdns_base_nameserver_ip_add(), than evdns_base_resume() will SEGFAULT,
because of NULL dereference in evdns_requests_pump_waiting_queue()
2013-05-13 19:56:00 +00:00
Nick Mathewson
ef820dbfb3 Merge remote-tracking branch 'origin/patches-2.0' 2013-05-07 10:03:28 -04:00
Belobrov Andrey
5c710c0362 Checking request nameserver for NULL, before using it. 2013-05-07 10:01:36 -04:00
Azat Khuzhin
6b7fa620e8 evdns: New flag to make evdns not prevent the event loop from exiting
Here is the brief description of problem:
When you are use evdns to resolve domains to IP adresses (see
./sample/dns-example) you loop never returns from event_base_dispatch(),
and because of this the program will never terminated.

Because existing programs may be depending on the old behavior, we
only apply the fix when evdns_base_new() is created with a new flag -
EVDNS_BASE_DISABLE_WHEN_INACTIVE.

 (Commit message edited by Nick while squashing the branch.)
2013-04-25 10:43:12 -04:00
Nick Mathewson
8827dbc3e9 Merge remote-tracking branch 'origin/patches-2.0' 2012-09-12 20:19:22 -04:00
George Danchev
f2bff75ed8 FIx another memleak on OOM in evdns 2012-09-12 20:12:03 -04:00
George Danchev
73e85dd08f Avoid a memory-leak on OOM in evdns. 2012-09-12 20:11:12 -04:00
Nick Mathewson
9be8624b2f Merge remote-tracking branch 'origin/patches-2.0' 2012-07-30 17:08:44 -04:00
Greg Hazel
dc3207767d Avoid segfault on weird timeout during name lookup.
If an evdns_getaddrinfo timeout happens while pending_cb is set, and
a callback is about to run, but we get a call to
evdns_getaddrinfo_gotresolve before it finishes.

Github issue #60. Thanks to Greg Hazel for patch and patience.
2012-07-30 17:01:52 -04:00
Nick Mathewson
9852107f37 Merge remote-tracking branch 'origin/patches-2.0'
Conflicts:
	buffer.c
	http.c
2012-07-26 10:43:13 -04:00
Nick Mathewson
a1a0e67531 memset sockaddr_in before using it. Found by coverity. 2012-07-26 10:38:29 -04:00
Nick Mathewson
c0e425abdc Restore our priority-inversion-prevention code with deferreds
Back when deferred_cb stuff had its own queue, the queue was always
executed, but we never ran more than 16 callbacks per iteration.
That made for two problems:

1: Because deferred_cb stuff would always run, and had no priority,
it could cause priority inversion.

2: It doesn't respect the max_dispatch_interval code.

Then, when I refactored deferred_cb to be a special case of
event_callback, that solved the above issues, but made for two more
issues:

3: Because deferred_cb stuff would always get the default priority,
it could could low-priority bufferevents to get too much priority.

4: With code like bufferevent_pair, it's easy to get into a
situation where two deferreds keep adding one another, preventing
the event loop from ever actually scanning for more events.

This commit fixes the above by giving deferreds a better notion of
priorities, and by limiting the number of deferreds that can be
added to the _current_ loop iteration's active queues.  (Extra
deferreds are put into the active_later state.)

That isn't an all-purpose priority inversion solution, of course: for
that, you may need to mess around with max_dispatch_interval.
2012-05-09 12:06:00 -04:00
Nick Mathewson
a4079aa88a Replace more deferred_cb names with event_callback 2012-05-09 12:05:59 -04:00
Nick Mathewson
ae2b84b257 Replace deferred_cbs with event_callback-based implementation. 2012-05-09 12:05:53 -04:00
Nick Mathewson
4b70286ef1 Merge remote-tracking branch 'origin/patches-2.0'
Conflicts:
	ChangeLog
	README
	evdns.c
	sample/dns-example.c
2012-05-02 17:12:23 -04:00
Nick Mathewson
265e6779dd Fix evdns build with threads disabled
The last evdns change apparently broke it, by using a "base"
variable that we were only declaring with threads turned on.
2012-05-02 16:52:27 -04:00
Nick Mathewson
3d9e52ac56 When retransmitting a timed-out DNS request, pick a fresh nameserver.
Otherwise, requests initially sent to a failing nameserver would
stay there indefinitely, even if other nameservers would work.

Fix for sourceforge bug 3518439
2012-05-01 19:52:55 -04:00
Nick Mathewson
d873d6787c Make some evdns.c debug logs more verbose 2012-05-01 19:52:49 -04:00
Nick Mathewson
3f659e5aeb Merge remote-tracking branch 'origin/patches-2.0' 2012-04-19 11:14:58 -04:00