mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Removed access to potentially invalid positions on vector.
This commit is contained in:
15
src/dns.cpp
15
src/dns.cpp
@@ -327,7 +327,7 @@ const uint8_t* DNS::compose_name(const uint8_t *ptr, char *out_ptr) const {
|
|||||||
std::memcpy(&index, ptr, sizeof(uint16_t));
|
std::memcpy(&index, ptr, sizeof(uint16_t));
|
||||||
index = Endian::be_to_host(index) & 0x3fff;
|
index = Endian::be_to_host(index) & 0x3fff;
|
||||||
// Check that the offset is neither too low or too high
|
// Check that the offset is neither too low or too high
|
||||||
if(index < 0x0c || &records_data[index - 0x0c] >= ptr)
|
if(index < 0x0c || (&records_data[0] + (index - 0x0c)) >= ptr)
|
||||||
throw malformed_packet();
|
throw malformed_packet();
|
||||||
// We've probably found the end of the original domain name. Save it.
|
// We've probably found the end of the original domain name. Save it.
|
||||||
if(end_ptr == 0)
|
if(end_ptr == 0)
|
||||||
@@ -494,6 +494,7 @@ uint8_t *DNS::update_dname(uint8_t *ptr, uint32_t threshold, uint32_t offset) {
|
|||||||
// Updates offsets in domain names inside records.
|
// Updates offsets in domain names inside records.
|
||||||
// No length checks, records are already valid.
|
// No length checks, records are already valid.
|
||||||
void DNS::update_records(uint32_t §ion_start, uint32_t num_records, uint32_t threshold, uint32_t offset) {
|
void DNS::update_records(uint32_t §ion_start, uint32_t num_records, uint32_t threshold, uint32_t offset) {
|
||||||
|
if(records_data.size() >= section_start) {
|
||||||
uint8_t *ptr = &records_data[section_start];
|
uint8_t *ptr = &records_data[section_start];
|
||||||
for(uint32_t i = 0; i < num_records; ++i) {
|
for(uint32_t i = 0; i < num_records; ++i) {
|
||||||
ptr = update_dname(ptr, threshold, offset);
|
ptr = update_dname(ptr, threshold, offset);
|
||||||
@@ -514,12 +515,15 @@ void DNS::update_records(uint32_t §ion_start, uint32_t num_records, uint32_t
|
|||||||
}
|
}
|
||||||
ptr += size;
|
ptr += size;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
section_start += offset;
|
section_start += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
DNS::queries_type DNS::queries() const {
|
DNS::queries_type DNS::queries() const {
|
||||||
queries_type output;
|
queries_type output;
|
||||||
const uint8_t *ptr = &records_data[0], *end = &records_data[answers_idx];
|
if(!records_data.empty()) {
|
||||||
|
const uint8_t *ptr = &records_data[0],
|
||||||
|
*end = &records_data[0] + answers_idx;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
uint16_t tmp_query_type;
|
uint16_t tmp_query_type;
|
||||||
uint16_t tmp_query_class;
|
uint16_t tmp_query_class;
|
||||||
@@ -538,36 +542,43 @@ DNS::queries_type DNS::queries() const {
|
|||||||
);
|
);
|
||||||
ptr += sizeof(uint16_t) * 2;
|
ptr += sizeof(uint16_t) * 2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
DNS::resources_type DNS::answers() const {
|
DNS::resources_type DNS::answers() const {
|
||||||
resources_type res;
|
resources_type res;
|
||||||
|
if(records_data.size() >= authority_idx) {
|
||||||
convert_records(
|
convert_records(
|
||||||
&records_data[answers_idx],
|
&records_data[answers_idx],
|
||||||
&records_data[authority_idx],
|
&records_data[authority_idx],
|
||||||
res
|
res
|
||||||
);
|
);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
DNS::resources_type DNS::authority() const {
|
DNS::resources_type DNS::authority() const {
|
||||||
resources_type res;
|
resources_type res;
|
||||||
|
if(records_data.size() >= additional_idx) {
|
||||||
convert_records(
|
convert_records(
|
||||||
&records_data[authority_idx],
|
&records_data[authority_idx],
|
||||||
&records_data[additional_idx],
|
&records_data[additional_idx],
|
||||||
res
|
res
|
||||||
);
|
);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
DNS::resources_type DNS::additional() const {
|
DNS::resources_type DNS::additional() const {
|
||||||
resources_type res;
|
resources_type res;
|
||||||
|
if(records_data.size() >= additional_idx) {
|
||||||
convert_records(
|
convert_records(
|
||||||
&records_data[additional_idx],
|
&records_data[additional_idx],
|
||||||
&records_data[records_data.size()],
|
&records_data[records_data.size()],
|
||||||
res
|
res
|
||||||
);
|
);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ PDU *IPv4Stream::allocate_pdu() const {
|
|||||||
}
|
}
|
||||||
return Internals::pdu_from_flag(
|
return Internals::pdu_from_flag(
|
||||||
static_cast<Constants::IP::e>(transport_proto),
|
static_cast<Constants::IP::e>(transport_proto),
|
||||||
&buffer[0],
|
buffer.empty() ? 0 : &buffer[0],
|
||||||
buffer.size()
|
buffer.size()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user