From roker at pep-project.org Fri Jul 28 07:37:54 2017 From: roker at pep-project.org (Lars Rohwedder) Date: Fri, 28 Jul 2017 09:37:54 +0200 Subject: [ldns-users] [ldns] Tutorial program crashes with segfault in ldns_rr_list_rr, (rr.c line 972) Message-ID: <488a7d7c-4dc0-61a5-0166-9be589fc44b1@pep-project.org> Hi there, I used the Tutorial #1 to learn how to use the ldns library. Unfortunately my program crashes within the ldns library, so I copied your original .c file and ? it also crashes. In gdb I got this stacktrace: Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7bb32fa in ldns_rr_list_rr (rr_list=rr_list at entry=0x603670, nr=nr at entry=0) at ./rr.c:972 972 ./rr.c: Datei oder Verzeichnis nicht gefunden. (gdb) bt #0 0x00007ffff7bb32fa in ldns_rr_list_rr (rr_list=rr_list at entry=0x603670, nr=nr at entry=0) at ./rr.c:972 #1 0x00007ffff7bb3a8b in ldns_rr_list_clone (rrlist=0x603670) at ./rr.c:1425 #2 0x00007ffff7bab90d in ldns_pkt_rr_list_by_type (packet=, type=LDNS_RR_TYPE_MX, sec=) at ./packet.c:296 #3 0x0000000000400dbb in main (argc=2, argv=0x7fffffffe0c8) at tutorial1.c:77 Platform: Ubuntu 16.04 LTS (Xenial Xerus), amd64 Compiler: gcc 5.4.0 LDNS-Version: 1.6.17-8 (shipped with Ubuntu) Is the LDNS-Version too old and this bug is known and fixed in newer versions? If yes, I should file a bug filed in the Ubuntu bugtracker. Thanks in advance for your help, Lars R. -------------- next part -------------- /* * mx is a small program that prints out the mx records * for a particular domain * (c) NLnet Labs, 2005 - 2008 * See the file LICENSE for the license */ #include static int usage(FILE *fp, char *prog) { fprintf(fp, "%s domain\n", prog); fprintf(fp, " print out the mx for domain\n"); return 0; } int main(int argc, char *argv[]) { ldns_resolver *res; ldns_rdf *domain; ldns_pkt *p; ldns_rr_list *mx; ldns_status s; p = NULL; mx = NULL; domain = NULL; res = NULL; if (argc != 2) { usage(stdout, argv[0]); exit(EXIT_FAILURE); } else { /* create a rdf from the command line arg */ domain = ldns_dname_new_frm_str(argv[1]); if (!domain) { usage(stdout, argv[0]); exit(EXIT_FAILURE); } if (! ldns_dname_str_absolute(argv[1]) && ldns_dname_absolute(domain)) { /* ldns_dname_new_frm_str makes absolute dnames always! * So deabsolutify domain. * TODO: Create ldns_dname_new_frm_str_relative? Yuck! */ ldns_rdf_set_size(domain, ldns_rdf_size(domain) - 1); } } /* create a new resolver from /etc/resolv.conf */ s = ldns_resolver_new_frm_file(&res, NULL); if (s != LDNS_STATUS_OK) { exit(EXIT_FAILURE); } /* use the resolver to send a query for the mx * records of the domain given on the command line */ p = ldns_resolver_search(res, domain, LDNS_RR_TYPE_MX, LDNS_RR_CLASS_IN, LDNS_RD); ldns_rdf_deep_free(domain); if (!p) { exit(EXIT_FAILURE); } else { /* retrieve the MX records from the answer section of that * packet */ mx = ldns_pkt_rr_list_by_type(p, LDNS_RR_TYPE_MX, LDNS_SECTION_ANSWER); if (!mx) { fprintf(stderr, " *** invalid answer name %s after MX query for %s\n", argv[1], argv[1]); ldns_pkt_free(p); ldns_resolver_deep_free(res); exit(EXIT_FAILURE); } else { ldns_rr_list_sort(mx); ldns_rr_list_print(stdout, mx); ldns_rr_list_deep_free(mx); } } ldns_pkt_free(p); ldns_resolver_deep_free(res); return 0; } -------------- next part -------------- A non-text attachment was scrubbed... Name: 0x88396C78.asc Type: application/pgp-keys Size: 3906 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From sca at andreasschulze.de Fri Jul 28 08:51:43 2017 From: sca at andreasschulze.de (A. Schulze) Date: Fri, 28 Jul 2017 10:51:43 +0200 Subject: [ldns-users] [ldns] Tutorial program crashes with segfault in ldns_rr_list_rr, (rr.c line 972) In-Reply-To: <488a7d7c-4dc0-61a5-0166-9be589fc44b1@pep-project.org> Message-ID: <20170728105143.Horde.tP-V34T_vLN761i6ciqPKPf@andreasschulze.de> Lars Rohwedder: > I used the Tutorial #1 to learn how to use the ldns library. have a look at https://getdnsapi.net/. As far as I learned it's more modern and actively maintained (by virtually the same people) I don't say, ldns is not maintained, but if you now today programming with ldns, just start with getdnsapi seem the better longterm approach to me. I use to compare like this: If you today start using a version control systems, you /may/ start with CVS, but starting with git seem more reasonable... Andreas