From: W.C.A. Wijngaards Date: Tue, 4 Apr 2017 14:36:50 +0000 (+0200) Subject: * ldns_wire2pkt: fix null pointer dereference if pkt allocation fails X-Git-Tag: release-1.7.1-rc1~78^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d8d141904bf79e7103a6dd0ed23e63d589ef99b;p=thirdparty%2Fldns.git * ldns_wire2pkt: fix null pointer dereference if pkt allocation fails and fix memory leak with more EDNS sections Thanks Jan Vcelak --- diff --git a/Changelog b/Changelog index 79f00aa1..fcf37cff 100644 --- a/Changelog +++ b/Changelog @@ -3,6 +3,9 @@ * bugfix #1209: make install ldns.pc file Thanks Oleksandr Natalenko * removed duplicate condition in ldns_udp_send_query. + * ldns_wire2pkt: fix null pointer dereference if pkt allocation fails + and fix memory leak with more EDNS sections + Thanks Jan Vcelak 1.7.0 2016-12-20 * Fix lookup of relative names in ldns_resolver_search. diff --git a/wire2host.c b/wire2host.c index 680d2f9d..a30e89e7 100644 --- a/wire2host.c +++ b/wire2host.c @@ -412,6 +412,10 @@ ldns_wire2pkt(ldns_pkt **packet_p, const uint8_t *wire, size_t max) uint8_t data[4]; + if (!packet) { + return LDNS_STATUS_MEM_ERR; + } + status = ldns_wire2pkt_hdr(packet, wire, max, &pos); LDNS_STATUS_CHECK_GOTO(status, status_error); @@ -464,6 +468,7 @@ ldns_wire2pkt(ldns_pkt **packet_p, const uint8_t *wire, size_t max) ldns_pkt_set_edns_z(packet, ldns_read_uint16(&data[2])); /* edns might not have rdfs */ if (ldns_rr_rdf(rr, 0)) { + ldns_rdf_deep_free(ldns_pkt_edns_data(packet)); ldns_pkt_set_edns_data(packet, ldns_rdf_clone(ldns_rr_rdf(rr, 0))); } ldns_rr_free(rr);