From: Jelte Jansen Date: Tue, 10 Jan 2023 10:56:51 +0000 (+0100) Subject: improve 'next-label' algorithm in ldns-walk X-Git-Tag: release-1.8.4-rc1~17^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F206%2Fhead;p=thirdparty%2Fldns.git improve 'next-label' algorithm in ldns-walk Rather than adding \000 to an existing label, add a new label "\000." to the start of the domain name, to find the closes next possible domain name. --- diff --git a/examples/ldns-walk.c b/examples/ldns-walk.c index 3710098a..f320b99d 100644 --- a/examples/ldns-walk.c +++ b/examples/ldns-walk.c @@ -38,24 +38,22 @@ create_dname_plus_1(ldns_rdf *dname) size_t i; ldns_dname2canonical(dname); - labellen = ldns_rdf_data(dname)[0]; if (verbosity >= 3) { printf("Create +e for "); ldns_rdf_print(stdout, dname); printf("\n"); } - if (labellen < 63) { - wire = malloc(ldns_rdf_size(dname) + 1); + if (ldns_rdf_size(dname) < LDNS_MAX_DOMAINLEN) { + wire = malloc(ldns_rdf_size(dname) + 2); if (!wire) { fprintf(stderr, "Malloc error: out of memory?\n"); exit(127); } - wire[0] = labellen + 1; - memcpy(&wire[1], ldns_rdf_data(dname) + 1, labellen); - memcpy(&wire[labellen+1], ldns_rdf_data(dname) + labellen, ldns_rdf_size(dname) - labellen); - wire[labellen+1] = (uint8_t) '\000'; + wire[0] = (uint8_t) 1; + wire[1] = (uint8_t) '\000'; + memcpy(&wire[2], ldns_rdf_data(dname), ldns_rdf_size(dname)); pos = 0; - status = ldns_wire2dname(&newdname, wire, ldns_rdf_size(dname) + 1, &pos); + status = ldns_wire2dname(&newdname, wire, ldns_rdf_size(dname) + 2, &pos); free(wire); } else { wire = malloc(ldns_rdf_size(dname)); @@ -63,6 +61,7 @@ create_dname_plus_1(ldns_rdf *dname) fprintf(stderr, "Malloc error: out of memory?\n"); exit(127); } + labellen = ldns_rdf_data(dname)[0]; wire[0] = labellen; memcpy(&wire[1], ldns_rdf_data(dname) + 1, labellen); memcpy(&wire[labellen], ldns_rdf_data(dname) + labellen, ldns_rdf_size(dname) - labellen);