On Tue, May 24, 2005 at 12:34:00AM +0200, Kurt Roeckx wrote:
> Using -g I can't reproduce it. It's also only the shared version
> that fails, the static version doesn't have the problem.
>
> I've attached a strace of the run causing the segfault.
>
> The backtrace of it looks like:
> Starting program: /usr/src/libdjbdns-1.05/src/test.shared
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x5556f3ce in dns_domain_length () from ./libdjbdns.so.1
> (gdb) bt
> #0 0x5556f3ce in dns_domain_length () from ./libdjbdns.so.1
> #1 0x08048771 in main () at test.c:17
> (gdb) frame 1
> #1 0x08048771 in main () at test.c:17
> 17 dns_domain_length(sa.s);
Ok, I still wasn't able to reproduce it, but it seems you're correct and
it's access to memory outside the accessible address space. I'm not
sure why this happens only on your system, the selftest is more than two
years old.
Please report whether the patch below works for you. If you have
improvements, please let me know also. Thanks, Gerrit.
Index: src/test.c
===================================================================
RCS file: /var/lib/cvs/libdjbdns/src/test.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 test.c
--- src/test.c 6 Dec 2002 15:42:46 -0000 1.1.1.1
+++ src/test.c 24 May 2005 07:56:00 -0000
@@ -3,10 +3,11 @@
int main () {
stralloc out ={0};
stralloc sa ={0};
- char ip[4];
+ char ip[4] ={127,0,0,1};
char *dn =0;
+ char *dn0 =0;
- stralloc_copys(&sa, "abcdefg");
+ stralloc_copys(&sa, "example.org");
dns_ip4(&out, &sa);
dns_ip4_qualify(&out, &sa, &sa);
@@ -14,10 +15,12 @@
dns_mx(&out, &sa);
dns_txt(&out, &sa);
- dns_domain_length(sa.s);
- dns_domain_equal(sa.s, sa.s);
- dns_domain_copy(&dn, sa.s);
- dns_domain_fromdot(&dn, sa.s, sa.len);
+ if (!dns_domain_fromdot(&dn, sa.s, sa.len)) return 1;
+ dns_domain_length(dn);
+ dns_domain_copy(&dn0, dn);
+ dns_domain_equal(dn0, dn);
+ dns_domain_free(&dn);
+ dns_domain_free(&dn0);
return 0;
}