str<<"\\# "<<(unsigned int)d_record.size()<<" ";
char hex[4];
for(size_t n=0; n<d_record.size(); ++n) {
- snprintf(hex,sizeof(hex)-1, "%02x", d_record.at(n));
+ snprintf(hex, sizeof(hex), "%02x", d_record.at(n));
str << hex;
}
return str.str();
dr.d_content=DNSRecordContent::mastermake(dr, pr, d_header.opcode);
}
- d_answers.push_back(make_pair(dr, pr.getPosition() - sizeof(dnsheader)));
-
/* XXX: XPF records should be allowed after TSIG as soon as the actual XPF option code has been assigned:
if (dr.d_place == DNSResourceRecord::ADDITIONAL && seenTSIG && dr.d_type != QType::XPF)
*/
seenTSIG = true;
d_tsigPos = recordStartPos;
}
+
+ d_answers.push_back(make_pair(std::move(dr), pr.getPosition() - sizeof(dnsheader)));
}
#if 0
else
stop_at = d_recordlen;
+ /* think unsigned overflow */
+ if (stop_at < d_pos) {
+ throw std::out_of_range("getUnquotedText out of record range");
+ }
+
if(stop_at == d_pos)
return "";
void PacketReader::xfrBlob(string& blob)
try
{
- if(d_recordlen && !(d_pos == (d_startrecordpos + d_recordlen)))
+ if(d_recordlen && !(d_pos == (d_startrecordpos + d_recordlen))) {
+ if (d_pos > (d_startrecordpos + d_recordlen)) {
+ throw std::out_of_range("xfrBlob out of record range");
+ }
blob.assign(&d_content.at(d_pos), &d_content.at(d_startrecordpos + d_recordlen - 1 ) + 1);
- else
+ }
+ else {
blob.clear();
+ }
d_pos = d_startrecordpos + d_recordlen;
}
void PacketReader::xfrBlob(string& blob, int length)
{
if(length) {
+ if (length < 0) {
+ throw std::out_of_range("xfrBlob out of range (negative length)");
+ }
+
blob.assign(&d_content.at(d_pos), &d_content.at(d_pos + length - 1 ) + 1 );
-
+
d_pos += length;
}
- else
+ else {
blob.clear();
+ }
}
: d_packet(packet), d_length(length), d_notyouroffset(12), d_offset(d_notyouroffset)
{}
- void skipLabel()
+ /*! Advances past a wire-format domain name
+ * The name is not checked for adherence to length restrictions.
+ * Compression pointers are not followed.
+ */
+ void skipDomainName()
{
uint8_t len;
while((len=get8BitInt())) {
skipBytes(len);
}
}
+
void skipBytes(uint16_t bytes)
{
moveOffset(bytes);
uint64_t n;
for(n=0; n < ntohs(dh.qdcount) ; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
/* type and class */
dpm.skipBytes(4);
}
for(n=0; n < numrecords; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
uint8_t section = n < ntohs(dh.ancount) ? 1 : (n < (ntohs(dh.ancount) + ntohs(dh.nscount)) ? 2 : 3);
uint16_t dnstype = dpm.get16BitInt();
uint64_t n;
for(n=0; n < dqcount; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
/* type and class */
dpm.skipBytes(4);
}
// cerr<<"Skipped "<<n<<" questions, now parsing "<<numrecords<<" records"<<endl;
for(n=0; n < numrecords; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
uint16_t dnstype = dpm.get16BitInt();
/* class */
const uint16_t qdcount = ntohs(dh->qdcount);
for(size_t n = 0; n < qdcount; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
/* type and class */
dpm.skipBytes(4);
}
const size_t numrecords = ntohs(dh->ancount) + ntohs(dh->nscount) + ntohs(dh->arcount);
for(size_t n = 0; n < numrecords; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
const uint16_t dnstype = dpm.get16BitInt();
/* class */
const uint16_t dnsclass = dpm.get16BitInt();
}
try
{
- const dnsheader* dh = (const dnsheader*) packet;
+ const dnsheader* dh = reinterpret_cast<const dnsheader*>(packet);
DNSPacketMangler dpm(const_cast<char*>(packet), length);
const uint16_t qdcount = ntohs(dh->qdcount);
for(size_t n = 0; n < qdcount; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
/* type and class */
dpm.skipBytes(4);
}
const size_t numrecords = ntohs(dh->ancount) + ntohs(dh->nscount) + ntohs(dh->arcount);
for(size_t n = 0; n < numrecords; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
/* type (2), class (2) and ttl (4) */
dpm.skipBytes(8);
dpm.skipRData();
const uint16_t qdcount = ntohs(dh->qdcount);
for(size_t n = 0; n < qdcount; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
if (section == 0) {
uint16_t dnstype = dpm.get16BitInt();
if (dnstype == type) {
}
const uint16_t ancount = ntohs(dh->ancount);
for(size_t n = 0; n < ancount; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
if (section == 1) {
uint16_t dnstype = dpm.get16BitInt();
if (dnstype == type) {
}
const uint16_t nscount = ntohs(dh->nscount);
for(size_t n = 0; n < nscount; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
if (section == 2) {
uint16_t dnstype = dpm.get16BitInt();
if (dnstype == type) {
}
const uint16_t arcount = ntohs(dh->arcount);
for(size_t n = 0; n < arcount; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
if (section == 3) {
uint16_t dnstype = dpm.get16BitInt();
if (dnstype == type) {
const uint16_t qdcount = ntohs(dh->qdcount);
for(size_t n = 0; n < qdcount; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
/* type and class */
dpm.skipBytes(4);
}
const size_t numrecords = ntohs(dh->ancount) + ntohs(dh->nscount) + ntohs(dh->arcount);
for(size_t n = 0; n < numrecords; ++n) {
- dpm.skipLabel();
+ dpm.skipDomainName();
const uint16_t dnstype = dpm.get16BitInt();
const uint16_t dnsclass = dpm.get16BitInt();