fix bug by adding null terminator

This commit is contained in:
AJ ONeal 2017-10-09 13:19:54 -06:00
parent ed28de4e59
commit ef3f2ae941
2 changed files with 19 additions and 16 deletions

View File

@ -1,3 +1,5 @@
// NOTE: this should be EXACTLY the same as PTR
(function (exports) {
'use strict';
@ -8,7 +10,9 @@ exports.DNS_PACKER_TYPE_NS = function (ab, dv, total, record) {
throw new Error("no data on NS record");
}
var rdLenIndex = total;
// RDLENGTH
// leading len and length of string and trailing null (all dots become lengths)
dv.setUint16(total, record.data.length + 2, false);
total += 2;
// RDATA
@ -23,9 +27,8 @@ exports.DNS_PACKER_TYPE_NS = function (ab, dv, total, record) {
total += 1;
});
});
// RDLENGTH
dv.setUint16(rdLenIndex, record.data.length + 1, false);
dv.setUint8(total, 0x00, false);
total += 1;
return total;
};

View File

@ -1,3 +1,5 @@
// NOTE: this should be EXACTLY the same as NS
(function (exports) {
'use strict';
@ -9,15 +11,14 @@ exports.DNS_PACKER_TYPE_PTR = function (ab, dv, total, record) {
throw new Error("no data for PTR record");
}
var ptrLen = 0;
var rdLenIndex = total;
// RDLENGTH
// leading len and length of string and trailing null (all dots become lengths)
dv.setUint16(total, record.data.length + 2, false);
total += 2;
// RDATA
// a sequence of labels
record.data.split('.').forEach(function (label) {
console.log("the labels are: " + label);
ptrLen += 1 + label.length;
dv.setUint8(total, label.length, false);
total += 1;
@ -27,9 +28,8 @@ exports.DNS_PACKER_TYPE_PTR = function (ab, dv, total, record) {
total += 1;
});
});
// RDLENGTH
dv.setUint16(rdLenIndex, record.data.length + 1, false);
dv.setUint8(total, 0x00, false);
total += 1;
return total;
};