From: Remi Gacogne Date: Tue, 21 Jun 2016 07:20:57 +0000 (+0200) Subject: Fix an invalid use of stack memory in dnspcap2protobuf X-Git-Tag: auth-4.0.0-rc1~27^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3bde188c39eb3469ac07dd59b138a73712bece01;p=pdns Fix an invalid use of stack memory in dnspcap2protobuf --- diff --git a/pdns/dnspcap2protobuf.cc b/pdns/dnspcap2protobuf.cc index 1a1e8d1ec..b66ef44bb 100644 --- a/pdns/dnspcap2protobuf.cc +++ b/pdns/dnspcap2protobuf.cc @@ -11,7 +11,7 @@ #include "statbag.hh" StatBag S; -static void addRRs(const char* packet, const size_t len, PBDNSMessage_DNSResponse& response) +static void addRRs(const char* packet, const size_t len, PBDNSMessage_DNSResponse* response) try { if (len < sizeof(struct dnsheader)) @@ -60,7 +60,7 @@ try pr.xfrBlob(blob); if (ah.d_type == QType::A || ah.d_type == QType::AAAA) { - PBDNSMessage_DNSResponse_DNSRR* rr = response.add_rrs(); + PBDNSMessage_DNSResponse_DNSRR* rr = response->add_rrs(); if (rr) { rr->set_name(rrname.toString()); rr->set_type(ah.d_type); @@ -145,8 +145,9 @@ int main(int argc, char **argv) } message.set_inbytes(pr.d_len); - PBDNSMessage_DNSQuestion question; - PBDNSMessage_DNSResponse response; + PBDNSMessage_DNSQuestion* question = message.mutable_question(); + PBDNSMessage_DNSResponse* response = message.mutable_response(); + if (!dh->qr) { boost::uuids::uuid uniqueId = uuidGenerator(); ids[dh->id] = uniqueId; @@ -162,27 +163,20 @@ int main(int argc, char **argv) std::copy(it->second.begin(), it->second.end(), messageId->begin()); } - response.set_rcode(dh->rcode); + response->set_rcode(dh->rcode); addRRs((const char*) dh, pr.d_len, response); - message.set_allocated_response(&response); } - question.set_qname(qname.toString()); - question.set_qtype(qtype); - question.set_qclass(qclass); - message.set_allocated_question(&question); + question->set_qname(qname.toString()); + question->set_qtype(qtype); + question->set_qclass(qclass); + std::string str; //cerr<qr) { - message.release_question(); - } - else { - message.release_response(); - } } fclose(fp); }