[ldns-users] [ldns] Tutorial program crashes with segfault in ldns_rr_list_rr, (rr.c line 972)

Lars Rohwedder roker at pep-project.org
Fri Jul 28 07:37:54 UTC 2017


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=<optimized
out>, type=LDNS_RR_TYPE_MX,
    sec=<optimized out>) 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 <ldns/ldns.h>
 
 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: <http://lists.nlnetlabs.nl/pipermail/ldns-users/attachments/20170728/82427209/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.nlnetlabs.nl/pipermail/ldns-users/attachments/20170728/82427209/attachment-0001.bin>


More information about the ldns-users mailing list