]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
fix incorrect copy error
authorTCY16 <tom@nlnetlabs.nl>
Mon, 20 Jun 2022 12:12:19 +0000 (14:12 +0200)
committerTCY16 <tom@nlnetlabs.nl>
Mon, 20 Jun 2022 12:12:19 +0000 (14:12 +0200)
testcode/testpkts.c

index a50bf3aee0dbcaaaa8be2c8a572e586e92a7c94e..123d460753d2b7ef65693b2faaa01bf7dc359035 100644 (file)
@@ -1778,17 +1778,20 @@ adjust_packet(struct entry* match, uint8_t** answer_pkt, size_t *answer_len,
        if(match->server_cookie) {
                /** Find the cookie option and add the server cookie if 
                 * the client cookie is present and not already there */
-               res = realloc(res, reslen + 28);
                uint8_t* walk_query = query_pkt;
                size_t walk_query_len = query_len;
-               uint8_t* walk_response = res;
-               size_t walk_response_len = reslen+28;
+               uint8_t* walk_response;
+               size_t walk_response_len;
 
-               uint8_t* rdlen_ptr_query;
                uint8_t* rdlen_ptr_response;
 
+               /* create space for the server cookie in the response packet */
+               res = realloc(res, reslen + 28);
                reslen += 28;
 
+               walk_response = res;
+               walk_response_len = reslen;
+
                if (!(walk_response)) {
                        log_err("testbound: out of memory; send without cookie");
                        return;
@@ -1818,7 +1821,6 @@ adjust_packet(struct entry* match, uint8_t** answer_pkt, size_t *answer_len,
                }
 
                /* store the location of the rdlen */
-               rdlen_ptr_query = walk_query + 6;
                rdlen_ptr_response = walk_response + 6;
 
                /* skip past the OPT record to get to the option */
@@ -1866,19 +1868,18 @@ adjust_packet(struct entry* match, uint8_t** answer_pkt, size_t *answer_len,
                        } else if (sldns_read_uint16(walk_query+2) == 24) {
                                /* we fake verification of the cookie and send
                                 * it back like it's still valid. We renew the cookie
-                                * if this desired*/
+                                * if this desired */
                                if (match->server_cookie_renew) {
                                        /* copy the cookie from the response but add a
                                         * different cookie (by reshuffeling server cookie) */
-                                       memcpy(rdlen_ptr_response, rdlen_ptr_query, 12);
-                                       memcpy(walk_response+12, rdlen_ptr_query+12+8, 8);
-                                       memcpy(walk_response+12+8, rdlen_ptr_query+12, 8);
+                                       memcpy(walk_response, walk_query, 12);
+                                       memcpy(walk_response+12, walk_query+12+8, 8);
+                                       memcpy(walk_response+12+8, walk_query+12, 8);
                                } else {
-                                       memcpy(rdlen_ptr_response, rdlen_ptr_query, 28);
+                                       memcpy(walk_response, walk_query, 28);
                                }
                        } else {
                                log_err("testbound: the incoming EDNS cookie has the wrong length");
-
                        }
                } else {
                        log_err("testbound: an error has occured while parsing the EDNS cookie");