File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,19 @@ class malformed_packet : public exception_base {
66
66
malformed_packet () : exception_base(" Malformed packet" ) { }
67
67
};
68
68
69
+ class DNS_decompression_pointer_out_of_bounds : public exception_base {
70
+ public:
71
+ DNS_decompression_pointer_out_of_bounds () : exception_base(" DNS decompression pointer out of bounds" ) { }
72
+ };
73
+
74
+ /* *
75
+ * \brief Exception thrown when a DNS decompression pointer loops.
76
+ */
77
+ class DNS_decompression_pointer_loops : public exception_base {
78
+ public:
79
+ DNS_decompression_pointer_loops () : exception_base(" DNS decompression pointer loops" ) { }
80
+ };
81
+
69
82
/* *
70
83
* \brief Exception thrown when serializing a packet fails.
71
84
*/
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
+ int 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