]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Revert "improve 'next-label' algorithm in ldns-walk"
authorWillem Toorop <willem@nlnetlabs.nl>
Mon, 17 Nov 2025 15:44:12 +0000 (16:44 +0100)
committerWillem Toorop <willem@nlnetlabs.nl>
Mon, 17 Nov 2025 15:44:12 +0000 (16:44 +0100)
This reverts commit 22a890681c91ac9f9f5070212a67b17371695b9b.

examples/ldns-walk.c

index d7f8459550fd93f3d8c84e2920c3b2f55dec93c6..8d767723c146a234f4a4eaf25c3d223f49e5bda3 100644 (file)
@@ -38,22 +38,24 @@ 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 (ldns_rdf_size(dname) < LDNS_MAX_DOMAINLEN) {
-               wire = malloc(ldns_rdf_size(dname) + 2);
+       if (labellen < 63) {
+               wire = malloc(ldns_rdf_size(dname) + 1);
                if (!wire) {
                        fprintf(stderr, "Malloc error: out of memory?\n");
                        exit(127);
                }
-               wire[0] = (uint8_t) 1;
-               wire[1] = (uint8_t) '\000';
-               memcpy(&wire[2], ldns_rdf_data(dname), ldns_rdf_size(dname));
+               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';
                pos = 0;
-               status = ldns_wire2dname(&newdname, wire, ldns_rdf_size(dname) + 2, &pos);
+               status = ldns_wire2dname(&newdname, wire, ldns_rdf_size(dname) + 1, &pos);
                free(wire);
        } else {
                wire = malloc(ldns_rdf_size(dname));
@@ -61,7 +63,6 @@ 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);