mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Fix DNS issues triggered on VC.
This commit is contained in:
22
src/dns.cpp
22
src/dns.cpp
@@ -242,7 +242,7 @@ void DNS::add_record(const Resource &resource, const sections_type §ions) {
|
||||
uint8_t *ptr = std::copy(
|
||||
buffer.begin(),
|
||||
buffer.end(),
|
||||
&records_data[threshold]
|
||||
&records_data[0] + threshold
|
||||
);
|
||||
|
||||
uint16_t uint16_t_buffer;
|
||||
@@ -502,7 +502,7 @@ uint8_t *DNS::update_dname(uint8_t *ptr, uint32_t threshold, uint32_t offset) {
|
||||
// Updates offsets in domain names inside records.
|
||||
// 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) {
|
||||
if(records_data.size() > section_start) {
|
||||
if(section_start < records_data.size()) {
|
||||
uint8_t *ptr = &records_data[section_start];
|
||||
for(uint32_t i = 0; i < num_records; ++i) {
|
||||
ptr = update_dname(ptr, threshold, offset);
|
||||
@@ -556,10 +556,10 @@ DNS::queries_type DNS::queries() const {
|
||||
|
||||
DNS::resources_type DNS::answers() const {
|
||||
resources_type res;
|
||||
if(records_data.size() >= authority_idx) {
|
||||
if(answers_idx < records_data.size()) {
|
||||
convert_records(
|
||||
&records_data[answers_idx],
|
||||
&records_data[authority_idx],
|
||||
&records_data[0] + answers_idx,
|
||||
&records_data[0] + authority_idx,
|
||||
res
|
||||
);
|
||||
}
|
||||
@@ -568,10 +568,10 @@ DNS::resources_type DNS::answers() const {
|
||||
|
||||
DNS::resources_type DNS::authority() const {
|
||||
resources_type res;
|
||||
if(records_data.size() >= additional_idx) {
|
||||
if(authority_idx < records_data.size()) {
|
||||
convert_records(
|
||||
&records_data[authority_idx],
|
||||
&records_data[additional_idx],
|
||||
&records_data[0] + authority_idx,
|
||||
&records_data[0] + additional_idx,
|
||||
res
|
||||
);
|
||||
}
|
||||
@@ -580,10 +580,10 @@ DNS::resources_type DNS::authority() const {
|
||||
|
||||
DNS::resources_type DNS::additional() const {
|
||||
resources_type res;
|
||||
if(records_data.size() >= additional_idx) {
|
||||
if(additional_idx < records_data.size()) {
|
||||
convert_records(
|
||||
&records_data[additional_idx],
|
||||
&records_data[records_data.size()],
|
||||
&records_data[0] + additional_idx,
|
||||
&records_data[0] + records_data.size(),
|
||||
res
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,6 +126,14 @@ TEST_F(DNSTest, ConstructorFromBuffer2) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DNSTest, NoRecords) {
|
||||
DNS dns;
|
||||
EXPECT_TRUE(dns.queries().empty());
|
||||
EXPECT_TRUE(dns.answers().empty());
|
||||
EXPECT_TRUE(dns.authority().empty());
|
||||
EXPECT_TRUE(dns.additional().empty());
|
||||
}
|
||||
|
||||
TEST_F(DNSTest, Serialization) {
|
||||
DNS dns(expected_packet, sizeof(expected_packet));
|
||||
DNS::serialization_type buffer = dns.serialize();
|
||||
|
||||
Reference in New Issue
Block a user