From 68d5b6bc5213b7eb411810361e04fe371ef19048 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 9 Jan 2011 18:54:45 -0500 Subject: Fix check for failed evdns request creation When using libevent 2, we use evdns_base_resolve_*(). When not, we fake evdns_base_resolve_*() using evdns_resolve_*(). Our old check was looking for negative values (like libevent 2 returns), but our eventdns.c code returns 1. This code makes the check just test for nonzero. Note that this broken check was not for _resolve_ failures or even for failures to _launch_ a resolve: it was for failures to _create_ or _encode_ a resolve request. Bug introduced in 81eee0ecfff3dac1e9438719d2f7dc0ba7e84a71; found by lodger; uploaded to trac by rransom. Bug 2363. Fix on 0.2.2.6-alpha. --- src/or/dns.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/or/dns.c') diff --git a/src/or/dns.c b/src/or/dns.c index 5c763011ba..639317112d 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -54,12 +54,16 @@ struct evdns_request; evdns_config_windows_nameservers() #define evdns_base_set_option_(base, opt, val) \ evdns_set_option((opt),(val),DNS_OPTIONS_ALL) +/* Note: our internal eventdns.c, plus libevent 1.4, used a 1 return to + * signify failure to launch a resolve. Libevent 2.0 uses a -1 return to + * signify a failure on a resolve, though if we're on libevent 2.0, we should + * have event2/dns.h and never hit these macros. Regardless, 0 is success. */ #define evdns_base_resolve_ipv4(base, addr, options, cb, ptr) \ - ((evdns_resolve_ipv4(addr, options, cb, ptr)<0) ? NULL : ((void*)1)) + ((evdns_resolve_ipv4(addr, options, cb, ptr)!=0) ? NULL : ((void*)1)) #define evdns_base_resolve_reverse(base, addr, options, cb, ptr) \ - ((evdns_resolve_reverse(addr, options, cb, ptr)<0) ? NULL : ((void*)1)) + ((evdns_resolve_reverse(addr, options, cb, ptr)!=0) ? NULL : ((void*)1)) #define evdns_base_resolve_reverse_ipv6(base, addr, options, cb, ptr) \ - ((evdns_resolve_reverse_ipv6(addr, options, cb, ptr)<0) ? NULL : ((void*)1)) + ((evdns_resolve_reverse_ipv6(addr, options, cb, ptr)!=0) ? NULL : ((void*)1)) #elif defined(LIBEVENT_VERSION_NUMBER) && LIBEVENT_VERSION_NUMBER < 0x02000303 #define evdns_base_set_option_(base, opt, val) \ -- cgit v1.2.3-54-g00ecf From efc9a84108903edf1d68b9f0c511538f15fc7f52 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 9 Jan 2011 19:05:06 -0500 Subject: Add missing parens to evdns_base_resolve_* macros while I am at it --- src/or/dns.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/or/dns.c') diff --git a/src/or/dns.c b/src/or/dns.c index 639317112d..dcccd1390d 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -54,16 +54,19 @@ struct evdns_request; evdns_config_windows_nameservers() #define evdns_base_set_option_(base, opt, val) \ evdns_set_option((opt),(val),DNS_OPTIONS_ALL) -/* Note: our internal eventdns.c, plus libevent 1.4, used a 1 return to +/* Note: our internal eventdns.c, plus Libevent 1.4, used a 1 return to * signify failure to launch a resolve. Libevent 2.0 uses a -1 return to - * signify a failure on a resolve, though if we're on libevent 2.0, we should + * signify a failure on a resolve, though if we're on Libevent 2.0, we should * have event2/dns.h and never hit these macros. Regardless, 0 is success. */ #define evdns_base_resolve_ipv4(base, addr, options, cb, ptr) \ - ((evdns_resolve_ipv4(addr, options, cb, ptr)!=0) ? NULL : ((void*)1)) -#define evdns_base_resolve_reverse(base, addr, options, cb, ptr) \ - ((evdns_resolve_reverse(addr, options, cb, ptr)!=0) ? NULL : ((void*)1)) -#define evdns_base_resolve_reverse_ipv6(base, addr, options, cb, ptr) \ - ((evdns_resolve_reverse_ipv6(addr, options, cb, ptr)!=0) ? NULL : ((void*)1)) + ((evdns_resolve_ipv4((addr), (options), (cb), (ptr))!=0) \ + ? NULL : ((void*)1)) +#define evdns_base_resolve_reverse(base, addr, options, cb, ptr) \ + ((evdns_resolve_reverse((addr), (options), (cb), (ptr))!=0) \ + ? NULL : ((void*)1)) +#define evdns_base_resolve_reverse_ipv6(base, addr, options, cb, ptr) \ + ((evdns_resolve_reverse_ipv6((addr), (options), (cb), (ptr))!=0) \ + ? NULL : ((void*)1)) #elif defined(LIBEVENT_VERSION_NUMBER) && LIBEVENT_VERSION_NUMBER < 0x02000303 #define evdns_base_set_option_(base, opt, val) \ -- cgit v1.2.3-54-g00ecf