File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -64,8 +64,26 @@ class option_not_found : public exception_base {
64
64
class malformed_packet : public exception_base {
65
65
public:
66
66
malformed_packet () : exception_base(" Malformed packet" ) { }
67
+ malformed_packet (const std::string& message) : exception_base(message) { }
67
68
};
68
69
70
+ /* *
71
+ * \brief Exception thrown when a DNS decompression pointer is out of bounds.
72
+ */
73
+ class dns_decompression_pointer_out_of_bounds : public malformed_packet {
74
+ public:
75
+ dns_decompression_pointer_out_of_bounds () : malformed_packet(" DNS decompression: pointer out of bounds" ) { }
76
+ };
77
+
78
+ /* *
79
+ * \brief Exception thrown when a DNS decompression pointer loops.
80
+ */
81
+ class dns_decompression_pointer_loops : public malformed_packet {
82
+ public:
83
+ dns_decompression_pointer_loops () : malformed_packet(" DNS decompression: pointer loops" ) { }
84
+ };
85
+
86
+
69
87
/* *
70
88
* \brief Exception thrown when serializing a packet fails.
71
89
*/
Original file line number Diff line number Diff line change @@ -336,7 +336,11 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const {
336
336
const uint8_t * end = &records_data_[0 ] + records_data_.size ();
337
337
const uint8_t * end_ptr = 0 ;
338
338
char * current_out_ptr = out_ptr;
339
+ uint8_t pointer_counter = 0 ;
339
340
while (*ptr) {
341
+ if (pointer_counter++ > 30 ){
342
+ throw dns_decompression_pointer_loops ();
343
+ }
340
344
// It's an offset
341
345
if ((*ptr & 0xc0 )) {
342
346
if (TINS_UNLIKELY (ptr + sizeof (uint16_t ) > end)) {
@@ -347,7 +351,7 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const {
347
351
index = Endian::be_to_host (index) & 0x3fff ;
348
352
// Check that the offset is neither too low or too high
349
353
if (index < 0x0c || (&records_data_[0 ] + (index - 0x0c )) >= end) {
350
- throw malformed_packet ();
354
+ throw dns_decompression_pointer_out_of_bounds ();
351
355
}
352
356
// We've probably found the end of the original domain name. Save it.
353
357
if (end_ptr == 0 ) {
You can’t perform that action at this time.
0 commit comments