]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
pkt: remove useless pointer sanitization in knot_pkt_free
authorDaniel Salzman <daniel.salzman@nic.cz>
Sat, 27 Jan 2018 14:07:44 +0000 (15:07 +0100)
committerDaniel Salzman <daniel.salzman@nic.cz>
Sat, 27 Jan 2018 14:07:48 +0000 (15:07 +0100)
13 files changed:
src/knot/nameserver/update.c
src/knot/query/requestor.c
src/knot/server/tcp-handler.c
src/knot/server/udp-handler.c
src/knot/zone/zone.c
src/libknot/packet/pkt.c
src/libknot/packet/pkt.h
src/utils/kdig/kdig_exec.c
src/utils/knsupdate/knsupdate_params.c
tests-fuzz/fuzz_packet.c
tests/libknot/test_pkt.c
tests/modules/test_rrl.c
tests/test_process_query.c

index d6a28558ce8cbef87285a399c19f01568d2a051d..5f499a4ca7af619aa49f728869747acaad8b3ec3 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -224,7 +224,7 @@ static int remote_forward(conf_t *conf, struct knot_request *request, conf_remot
        knot_pkt_t *query = knot_pkt_new(NULL, request->query->max_size, NULL);
        int ret = knot_pkt_copy(query, request->query);
        if (ret != KNOT_EOK) {
-               knot_pkt_free(&query);
+               knot_pkt_free(query);
                return ret;
        }
        knot_wire_set_id(query->wire, dnssec_random_uint16_t());
@@ -240,7 +240,7 @@ static int remote_forward(conf_t *conf, struct knot_request *request, conf_remot
        struct knot_requestor re;
        ret = knot_requestor_init(&re, capture, &capture_param, NULL);
        if (ret != KNOT_EOK) {
-               knot_pkt_free(&query);
+               knot_pkt_free(query);
                return ret;
        }
 
@@ -250,7 +250,7 @@ static int remote_forward(conf_t *conf, struct knot_request *request, conf_remot
        struct knot_request *req = knot_request_make(re.mm, dst, src, query, NULL, 0);
        if (req == NULL) {
                knot_requestor_clear(&re);
-               knot_pkt_free(&query);
+               knot_pkt_free(query);
                return KNOT_ENOMEM;
        }
 
@@ -356,8 +356,8 @@ static void send_update_response(conf_t *conf, const zone_t *zone, struct knot_r
 static void free_request(struct knot_request *req)
 {
        close(req->fd);
-       knot_pkt_free(&req->query);
-       knot_pkt_free(&req->resp);
+       knot_pkt_free(req->query);
+       knot_pkt_free(req->resp);
        free(req);
 }
 
index 46af6867e07e0be8aef75eb4a109adcc8b0641ee..d28b9c94ab75a044dbf1b11fe7cc68c691b11ad4 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -156,8 +156,8 @@ void knot_request_free(struct knot_request *request, knot_mm_t *mm)
        if (request->fd >= 0) {
                close(request->fd);
        }
-       knot_pkt_free(&request->query);
-       knot_pkt_free(&request->resp);
+       knot_pkt_free(request->query);
+       knot_pkt_free(request->resp);
        tsig_cleanup(&request->tsig);
 
        mm_free(mm, request);
index 435f3907d418f6d4974b90d81a80caeaa599d767..463544485cc3ac09125a98671e08c2ff5ec4da4f 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -168,8 +168,8 @@ static int tcp_handle(tcp_context_t *tcp, int fd,
        knot_layer_finish(&tcp->layer);
 
        /* Cleanup. */
-       knot_pkt_free(&query);
-       knot_pkt_free(&ans);
+       knot_pkt_free(query);
+       knot_pkt_free(ans);
 
        return ret;
 }
index 535e2e6e24a86803dc62474559ffb9c7934e6494..1241d982e7702042b7c76f484f1cea26c587cdc2 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -100,8 +100,8 @@ static void udp_handle(udp_context_t *udp, int fd, struct sockaddr_storage *ss,
        knot_layer_finish(&udp->layer);
 
        /* Cleanup. */
-       knot_pkt_free(&query);
-       knot_pkt_free(&ans);
+       knot_pkt_free(query);
+       knot_pkt_free(ans);
 }
 
 /*! \brief Pointer to selected UDP master implementation. */
index bfb74bf53da3f338e73b44ca79807a5dd08867a4..fbccd0b523f7f4dd163f67da103b3a05a83ee7f9 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -555,7 +555,7 @@ int zone_update_enqueue(zone_t *zone, knot_pkt_t *pkt, knotd_qdata_params_t *par
        req->query = knot_pkt_new(NULL, pkt->max_size, NULL);
        int ret = knot_pkt_copy(req->query, pkt);
        if (ret != KNOT_EOK) {
-               knot_pkt_free(&req->query);
+               knot_pkt_free(req->query);
                free(req);
                return ret;
        }
index 8ed1b712d74136cf19f8bf2e2e1e8b74d8872db7..414bc14c286fc8e404b6ddb5877098039930c29a 100644 (file)
@@ -378,26 +378,25 @@ void knot_pkt_clear(knot_pkt_t *pkt)
 }
 
 _public_
-void knot_pkt_free(knot_pkt_t **pkt)
+void knot_pkt_free(knot_pkt_t *pkt)
 {
-       if (pkt == NULL || *pkt == NULL) {
+       if (pkt == NULL) {
                return;
        }
 
        /* Free temporary RRSets. */
-       pkt_free_data(*pkt);
+       pkt_free_data(pkt);
 
        /* Free RR/RR info arrays. */
-       mm_free(&(*pkt)->mm, (*pkt)->rr);
-       mm_free(&(*pkt)->mm, (*pkt)->rr_info);
+       mm_free(&pkt->mm, pkt->rr);
+       mm_free(&pkt->mm, pkt->rr_info);
 
        // free the space for wireformat
-       if ((*pkt)->flags & KNOT_PF_FREE) {
-               mm_free(&(*pkt)->mm, (*pkt)->wire);
+       if (pkt->flags & KNOT_PF_FREE) {
+               mm_free(&pkt->mm, pkt->wire);
        }
 
-       mm_free(&(*pkt)->mm, *pkt);
-       *pkt = NULL;
+       mm_free(&pkt->mm, pkt);
 }
 
 _public_
index 9889a787a83b17c4e7c31888ef50833586074194..891e7513bfd2391f1831743d02be6ad285a1e7a9 100644 (file)
@@ -139,7 +139,7 @@ int knot_pkt_init_response(knot_pkt_t *pkt, const knot_pkt_t *query);
 void knot_pkt_clear(knot_pkt_t *pkt);
 
 /*! \brief Begone you foul creature of the underworld. */
-void knot_pkt_free(knot_pkt_t **pkt);
+void knot_pkt_free(knot_pkt_t *pkt);
 
 /*!
  * \brief Reserve an arbitrary amount of space in the packet.
index 3dad5dc0dda9d43d7aa9f215a8e4e18ff63d95fd..f668f80e55104abacca576ba9b6ceceafaac8f72 100644 (file)
@@ -235,7 +235,7 @@ static void process_dnstap(const query_t *query)
                        ERR("can't print dnstap message\n");
                }
 
-               knot_pkt_free(&pkt);
+               knot_pkt_free(pkt);
                dt_reader_free_frame(reader, &frame);
        }
 }
@@ -412,7 +412,7 @@ static knot_pkt_t *create_query_packet(const query_t *query)
        // Create QNAME from string.
        knot_dname_t *qname = knot_dname_from_str_alloc(query->owner);
        if (qname == NULL) {
-               knot_pkt_free(&packet);
+               knot_pkt_free(packet);
                return NULL;
        }
 
@@ -421,7 +421,7 @@ static knot_pkt_t *create_query_packet(const query_t *query)
                                        query->type_num);
        if (ret != KNOT_EOK) {
                knot_dname_free(&qname, NULL);
-               knot_pkt_free(&packet);
+               knot_pkt_free(packet);
                return NULL;
        }
 
@@ -444,7 +444,7 @@ static knot_pkt_t *create_query_packet(const query_t *query)
                                                   &packet->mm);
                knot_dname_free(&qname, NULL);
                if (soa == NULL) {
-                       knot_pkt_free(&packet);
+                       knot_pkt_free(packet);
                        return NULL;
                }
 
@@ -452,7 +452,7 @@ static knot_pkt_t *create_query_packet(const query_t *query)
                ret = knot_rrset_add_rdata(soa, wire, sizeof(wire), &packet->mm);
                if (ret != KNOT_EOK) {
                        knot_rrset_free(&soa, &packet->mm);
-                       knot_pkt_free(&packet);
+                       knot_pkt_free(packet);
                        return NULL;
                }
 
@@ -462,7 +462,7 @@ static knot_pkt_t *create_query_packet(const query_t *query)
                ret = knot_pkt_put(packet, KNOT_COMPR_HINT_NONE, soa, KNOT_PF_FREE);
                if (ret != KNOT_EOK) {
                        knot_rrset_free(&soa, &packet->mm);
-                       knot_pkt_free(&packet);
+                       knot_pkt_free(packet);
                        return NULL;
                }
 
@@ -479,7 +479,7 @@ static knot_pkt_t *create_query_packet(const query_t *query)
                int ret = add_query_edns(packet, query, max_size);
                if (ret != KNOT_EOK) {
                        ERR("can't set up EDNS section\n");
-                       knot_pkt_free(&packet);
+                       knot_pkt_free(packet);
                        return NULL;
                }
        }
@@ -636,7 +636,7 @@ static int process_query_packet(const knot_pkt_t      *query,
                        } else {
                                ERR("can't print query packet\n");
                        }
-                       knot_pkt_free(&q);
+                       knot_pkt_free(q);
                } else {
                        ERR("can't print query packet\n");
                }
@@ -675,7 +675,7 @@ static int process_query_packet(const knot_pkt_t      *query,
                // Parse reply to the packet structure.
                if (knot_pkt_parse(reply, KNOT_PF_NOCANON) != KNOT_EOK) {
                        ERR("malformed reply packet from %s\n", net->remote_str);
-                       knot_pkt_free(&reply);
+                       knot_pkt_free(reply);
                        net_close(net);
                        return 0;
                }
@@ -685,12 +685,12 @@ static int process_query_packet(const knot_pkt_t      *query,
                        break;
                // Check for timeout.
                } else if (time_diff_ms(&t_query, &t_end) > 1000 * net->wait) {
-                       knot_pkt_free(&reply);
+                       knot_pkt_free(reply);
                        net_close(net);
                        return -1;
                }
 
-               knot_pkt_free(&reply);
+               knot_pkt_free(reply);
        }
 
        // Check for TC bit and repeat query with TCP if required.
@@ -699,7 +699,7 @@ static int process_query_packet(const knot_pkt_t      *query,
                printf("\n");
                WARN("truncated reply from %s, retrying over TCP\n\n",
                     net->remote_str);
-               knot_pkt_free(&reply);
+               knot_pkt_free(reply);
                net_close(net);
 
                net->socktype = SOCK_STREAM;
@@ -740,7 +740,7 @@ static int process_query_packet(const knot_pkt_t      *query,
                uint8_t *opt = knot_edns_get_option(reply->opt_rr, KNOT_EDNS_OPTION_COOKIE);
                if (opt == NULL) {
                        ERR("bad cookie, missing EDNS section\n");
-                       knot_pkt_free(&reply);
+                       knot_pkt_free(reply);
                        return -1;
                }
 
@@ -749,11 +749,11 @@ static int process_query_packet(const knot_pkt_t      *query,
                int ret = knot_edns_cookie_parse(&new_ctx.cc, &new_ctx.sc,
                                                 data, data_len);
                if (ret != KNOT_EOK) {
-                       knot_pkt_free(&reply);
+                       knot_pkt_free(reply);
                        ERR("bad cookie, missing EDNS cookie option\n");
                        return -1;
                }
-               knot_pkt_free(&reply);
+               knot_pkt_free(reply);
 
                // Restore the original client cookie.
                new_ctx.cc = query_ctx->cc;
@@ -761,12 +761,12 @@ static int process_query_packet(const knot_pkt_t      *query,
                knot_pkt_t *new_query = create_query_packet(&new_ctx);
                ret = process_query_packet(new_query, net, &new_ctx, ignore_tc,
                                           sign_ctx, style);
-               knot_pkt_free(&new_query);
+               knot_pkt_free(new_query);
 
                return ret;
        }
 
-       knot_pkt_free(&reply);
+       knot_pkt_free(reply);
        net_close(net);
 
        return 0;
@@ -846,7 +846,7 @@ static void process_query(const query_t *query)
                        if (ret == 0) {
                                net_clean(&net);
                                sign_context_deinit(&sign_ctx);
-                               knot_pkt_free(&out_packet);
+                               knot_pkt_free(out_packet);
                                return;
                        }
 
@@ -870,7 +870,7 @@ static void process_query(const query_t *query)
        }
 
        sign_context_deinit(&sign_ctx);
-       knot_pkt_free(&out_packet);
+       knot_pkt_free(out_packet);
 }
 
 static int process_xfr_packet(const knot_pkt_t      *query,
@@ -930,7 +930,7 @@ static int process_xfr_packet(const knot_pkt_t      *query,
                        } else {
                                ERR("can't print query packet\n");
                        }
-                       knot_pkt_free(&q);
+                       knot_pkt_free(q);
                } else {
                        ERR("can't print query packet\n");
                }
@@ -969,7 +969,7 @@ static int process_xfr_packet(const knot_pkt_t      *query,
                // Parse reply to the packet structure.
                if (knot_pkt_parse(reply, 0) != KNOT_EOK) {
                        ERR("malformed reply packet from %s\n", net->remote_str);
-                       knot_pkt_free(&reply);
+                       knot_pkt_free(reply);
                        net_close(net);
                        return 0;
                }
@@ -977,7 +977,7 @@ static int process_xfr_packet(const knot_pkt_t      *query,
                // Compare reply header id.
                if (check_reply_id(reply, query) == false) {
                        ERR("reply ID mismatch from %s\n", net->remote_str);
-                       knot_pkt_free(&reply);
+                       knot_pkt_free(reply);
                        net_close(net);
                        return 0;
                }
@@ -991,7 +991,7 @@ static int process_xfr_packet(const knot_pkt_t      *query,
                if (knot_pkt_ext_rcode(reply) != KNOT_RCODE_NOERROR) {
                        ERR("server replied with error '%s'\n",
                            knot_pkt_ext_rcode_name(reply));
-                       knot_pkt_free(&reply);
+                       knot_pkt_free(reply);
                        net_close(net);
                        return 0;
                }
@@ -1011,7 +1011,7 @@ static int process_xfr_packet(const knot_pkt_t      *query,
 
                                        ERR("reply verification for %s (%s)\n",
                                            net->remote_str, knot_strerror(ret));
-                                       knot_pkt_free(&reply);
+                                       knot_pkt_free(reply);
                                        net_close(net);
                                        return 0;
                                }
@@ -1023,7 +1023,7 @@ static int process_xfr_packet(const knot_pkt_t      *query,
                        if (serial < 0) {
                                ERR("first answer record from %s isn't SOA\n",
                                    net->remote_str);
-                               knot_pkt_free(&reply);
+                               knot_pkt_free(reply);
                                net_close(net);
                                return 0;
                        }
@@ -1044,11 +1044,11 @@ static int process_xfr_packet(const knot_pkt_t      *query,
 
                // Check for finished transfer.
                if (finished_xfr(serial, reply, msg_count, query_ctx->serial != -1)) {
-                       knot_pkt_free(&reply);
+                       knot_pkt_free(reply);
                        break;
                }
 
-               knot_pkt_free(&reply);
+               knot_pkt_free(reply);
        }
 
        // Get stop reply time.
@@ -1107,7 +1107,7 @@ static void process_xfr(const query_t *query)
                       flags, &query->tls, &net);
        if (ret != KNOT_EOK) {
                sign_context_deinit(&sign_ctx);
-               knot_pkt_free(&out_packet);
+               knot_pkt_free(out_packet);
                return;
        }
 
@@ -1133,7 +1133,7 @@ static void process_xfr(const query_t *query)
 
        net_clean(&net);
        sign_context_deinit(&sign_ctx);
-       knot_pkt_free(&out_packet);
+       knot_pkt_free(out_packet);
 }
 
 int kdig_exec(const kdig_params_t *params)
index 19aa223a42d6e48b5682d6ffa34064421e0f758a..f1b067e366c4f6e17f41a3f34ffe298b03df6ffa 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -146,8 +146,8 @@ void knsupdate_clean(knsupdate_params_t *params)
        srv_info_free(params->srcif);
        free(params->zone);
        zs_deinit(&params->parser);
-       knot_pkt_free(&params->query);
-       knot_pkt_free(&params->answer);
+       knot_pkt_free(params->query);
+       knot_pkt_free(params->answer);
        knot_tsig_key_deinit(&params->tsig_key);
 
        /* Clean up the structure. */
index 0d8dae05cf3d3167220ec1085957ea6e84a07840..ad9c086abd5710277ffab4ca136a517a5dd04607 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
        knot_pkt_t *pkt = knot_pkt_new(copy, size, NULL);
        assert(pkt);
        knot_pkt_parse(pkt, 0);
-       knot_pkt_free(&pkt);
+       knot_pkt_free(pkt);
 
        return 0;
 }
index 661a54e6e7429babd4a5d3b4342e69d65471981a..e14361ba14d7e9c7e2aa9f61f23cd31be9bf559e 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -188,10 +188,9 @@ int main(int argc, char *argv[])
        packet_match(in, copy);
 
        /* Free packets. */
-       knot_pkt_free(&copy);
-       knot_pkt_free(&out);
-       knot_pkt_free(&in);
-       ok(in == NULL && out == NULL && copy == NULL, "pkt: free");
+       knot_pkt_free(copy);
+       knot_pkt_free(out);
+       knot_pkt_free(in);
 
        /* Free extra data. */
        for (unsigned i = 0; i < NAMECOUNT; ++i) {
index 24dcc7b1b444cb0b34f221e27a23bd9518d71d85..5d13c599fcdfe55921be6a87b80902c6235b2848 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
        int ret = knot_pkt_put_question(query, qname, KNOT_CLASS_IN, KNOT_RRTYPE_A);
        knot_dname_free(&qname, NULL);
        if (ret != KNOT_EOK) {
-               knot_pkt_free(&query);
+               knot_pkt_free(query);
                return KNOT_ERROR; /* Fatal */
        }
 
@@ -160,7 +160,7 @@ int main(int argc, char *argv[])
 #endif
 
        knot_dname_free(&zone, NULL);
-       knot_pkt_free(&query);
+       knot_pkt_free(query);
        rrl_destroy(rrl);
        dnssec_crypto_cleanup();
        return 0;
index b6c42d341bc8005bdffdc6555aa2d82fe4583223..aa678773a814f7b238f3caaadea36e836df5b890 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -68,7 +68,7 @@ static void exec_query(knot_layer_t *layer, const char *name,
        /* Check answer. */
        answer_sanity_check(query->wire, answer->wire, answer->size, expected_rcode, name);
 
-       knot_pkt_free(&answer);
+       knot_pkt_free(answer);
 }
 
 /* \internal Helpers */