summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dns_record.cpp7
-rw-r--r--src/ip.cpp6
-rw-r--r--src/rsn_information.cpp9
3 files changed, 13 insertions, 9 deletions
diff --git a/src/dns_record.cpp b/src/dns_record.cpp
index 7555e1a..e64127e 100644
--- a/src/dns_record.cpp
+++ b/src/dns_record.cpp
@@ -29,6 +29,7 @@
#include <cstring>
#include <stdexcept>
+#include <memory>
#include <typeinfo>
#include "dns_record.h"
#include "endianness.h"
@@ -50,10 +51,11 @@ DNSResourceRecord::DNSResourceRecord(DNSRRImpl *impl,
DNSResourceRecord::DNSResourceRecord(const uint8_t *buffer, uint32_t size)
{
const uint8_t *buffer_end = buffer + size;
+ std::auto_ptr<DNSRRImpl> tmp_impl;
if((*buffer & 0xc0)) {
uint16_t offset(*reinterpret_cast<const uint16_t*>(buffer));
offset = Endian::be_to_host(offset) & 0x3fff;
- impl = new OffsetedDNSRRImpl(Endian::host_to_be(offset));
+ tmp_impl.reset(new OffsetedDNSRRImpl(Endian::host_to_be(offset)));
buffer += sizeof(uint16_t);
}
else {
@@ -63,7 +65,7 @@ DNSResourceRecord::DNSResourceRecord(const uint8_t *buffer, uint32_t size)
if(str_end == buffer_end)
throw std::runtime_error("Not enough size for a resource domain name.");
//str_end++;
- impl = new NamedDNSRRImpl(buffer, str_end);
+ tmp_impl.reset(new NamedDNSRRImpl(buffer, str_end));
buffer = ++str_end;
}
if(buffer + sizeof(info_) > buffer_end)
@@ -86,6 +88,7 @@ DNSResourceRecord::DNSResourceRecord(const uint8_t *buffer, uint32_t size)
*(uint32_t*)&data[0] = *(uint32_t*)buffer;
else
throw std::runtime_error("Not enough size for resource data");
+ impl = tmp_impl.release();
}
DNSResourceRecord::DNSResourceRecord(const DNSResourceRecord &rhs)
diff --git a/src/ip.cpp b/src/ip.cpp
index dca65f7..f105844 100644
--- a/src/ip.cpp
+++ b/src/ip.cpp
@@ -77,7 +77,7 @@ IP::IP(const uint8_t *buffer, uint32_t total_sz)
buffer += head_len() * sizeof(uint32_t);
_options_size = 0;
- _padded_options_size = head_len() * sizeof(uint32_t) - sizeof(iphdr);
+ //_padded_options_size = head_len() * sizeof(uint32_t) - sizeof(iphdr);
/* While the end of the options is not reached read an option */
while (ptr_buffer < buffer && (*ptr_buffer != 0)) {
//ip_option opt_to_add;
@@ -126,6 +126,8 @@ IP::IP(const uint8_t *buffer, uint32_t total_sz)
}
_options_size += _ip_options.back().data_size() + 2;
}
+ uint8_t padding = _options_size % 4;
+ _padded_options_size = padding ? (_options_size - padding + 4) : _options_size;
// check this line PLX
total_sz -= head_len() * sizeof(uint32_t);
if (total_sz) {
@@ -304,7 +306,7 @@ uint16_t IP::stream_identifier() const {
void IP::add_option(const ip_option &option) {
_ip_options.push_back(option);
_options_size += 1 + option.data_size();
- uint8_t padding = _options_size & 3;
+ uint8_t padding = _options_size % 4;
_padded_options_size = padding ? (_options_size - padding + 4) : _options_size;
}
diff --git a/src/rsn_information.cpp b/src/rsn_information.cpp
index f730061..a441518 100644
--- a/src/rsn_information.cpp
+++ b/src/rsn_information.cpp
@@ -51,21 +51,20 @@ RSNInformation::RSNInformation(const uint8_t *buffer, uint32_t total_sz) {
void RSNInformation::init(const uint8_t *buffer, uint32_t total_sz) {
const char *err_msg = "Malformed RSN information structure";
- check_size<uint16_t>(total_sz, err_msg);
+ if(total_sz <= sizeof(uint16_t) * 2 + sizeof(uint32_t))
+ throw std::runtime_error(err_msg);
version(Endian::le_to_host(*(uint16_t*)buffer));
buffer += sizeof(uint16_t);
total_sz -= sizeof(uint16_t);
- group_suite((RSNInformation::CypherSuites)*(uint32_t*)buffer);
- check_size<uint32_t>(total_sz, err_msg);
+ group_suite((RSNInformation::CypherSuites)*(uint32_t*)buffer);
buffer += sizeof(uint32_t);
total_sz -= sizeof(uint32_t);
- check_size<uint16_t>(total_sz, err_msg);
-
uint16_t count = *(uint16_t*)buffer;
buffer += sizeof(uint16_t);
total_sz -= sizeof(uint16_t);
+
if(count * sizeof(uint32_t) > total_sz)
throw std::runtime_error(err_msg);
total_sz -= count * sizeof(uint32_t);