How to use "dns_new()" (I get "dns_new: Assertion `(copy->dnsc_flags & DNS_INITED)' failed")

Michael Tokarev mjt at tls.msk.ru
Sat Feb 5 21:01:47 MSK 2011


05.02.2011 20:51, Iñaki Baz Castillo wrote:
> 2011/2/5 Michael Tokarev <mjt at tls.msk.ru>:
>>> If I omit the line "dns_init(dns_context, 0)" then it doesn't work
>>> well (please check my other mail with subject "Problem when non using
>>> default ctx" in which I report it).
>>
>> dns_new() returns initialized but not open context.
>> In the above sequence there's no need to call dns_init()
>> twice.
> 
> This is what I expected, but if I remove the second "dns_init()" line
> then strange things happen when the queried domain doesn't exist (it
> takes 31 seconds to end the script).
[]
> If you leave the second dns_init() uncommeted and query a non existing
> domain you get an instant "ERROR: no DNS result".
> 
> But if you comment the second dns_init() it takes 31 seconds to
> terminate and performs invalid/malformed DNS queries after receiving
> the response "0011 No such name"). I've checked it with tcpdump and
> wireshark.

invalid queries is a good indicator of some issue.  Please try without
second init but give it absolute domain name (the one which ends with
a dot) - it should complete immediately.

> NOTE: I use udns 0.9 version (Ubuntu). Could this issue make reference
> to a change in 1.0?:
> 
> 0.1 (Dec 2010)
>  - bugfix: udns_new(old) - when actually cloning another context -
>    makes the new context referencing memory from old, which leads
>    to crashes when old is modified later

Yes, that's quite possible consequence too.

I just verified with 0.1 (note it's not 0.9 and 1.0, it's 0.0.9 and 0.1 ;),
and it works just fine.  The fix is trivial:

Index: udns_resolver.c
diff -p -u -r1.98 -r1.99
--- udns_resolver.c	10 Jan 2007 13:32:33 -0000	1.98
+++ udns_resolver.c	1 Dec 2010 14:33:48 -0000	1.99
@@ -467,6 +467,8 @@ struct dns_ctx *dns_new(const struct dns
   ctx->dnsc_nactive = 0;
   ctx->dnsc_pbuf = NULL;
   ctx->dnsc_qstatus = 0;
+  ctx->dnsc_srchend = ctx->dnsc_srchbuf +
+    (copy->dnsc_srchend - copy->dnsc_srchbuf);
   ctx->dnsc_utmfn = NULL;
   ctx->dnsc_utmctx = NULL;
   ctx->dnsc_nextid = dns_random16();


However, even without the fix, it should not time out -
unless it produces really bogus queries.  Which queries
it performs?

/mjt


More information about the udns mailing list