Skip to content

Commit

Permalink
Don't crash on domain names ending in a point
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaxxz committed May 2, 2015
1 parent f1796ea commit 802e02d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions decode/dns/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ exports.decodeName = function(raw_packet, offset) {
var initialOffset = offset;
var result = { bytesDecoded:undefined, name:"" };

if(raw_packet[offset] > 63) {
//Name is in pointer format which is currently not supported
result.bytesDecoded = 2;
result.name = "";
return result;
}

while((segLength = raw_packet[offset++]) !== 0 && segLength < 63) {
while((segLength = raw_packet[offset++]) !== 0 && segLength <= 63) {
if(firstSegment) {
firstSegment = false;
} else {
Expand All @@ -22,6 +15,15 @@ exports.decodeName = function(raw_packet, offset) {
result.name += String.fromCharCode(raw_packet[offset++]);
}
}

if(raw_packet[offset-1] > 63) {
// Detected a pointer, pointers
// are 2 bytes long so inc the offset
// At this time we have very poor support
// for pointers
offset++;
}

result.bytesDecoded = offset - initialOffset;
return result;
};

0 comments on commit 802e02d

Please sign in to comment.