note if data is truncated
This commit is contained in:
parent
ef3f2ae941
commit
471a80638d
12
bin/debug.js
12
bin/debug.js
|
@ -65,6 +65,11 @@ function unpackQuestionLabels(opts) {
|
|||
|
||||
while (true) {
|
||||
if (total >= len) {
|
||||
opts.trunc = true;
|
||||
console.warn('');
|
||||
console.warn('[WARNING] The label was truncated by byte length of message or rdata.');
|
||||
console.warn('[WARNING] Depending on the Resource Record type, that may be a parse error.');
|
||||
console.warn('');
|
||||
break;
|
||||
}
|
||||
labelLen = dv.getUint8(total, false); // additional count
|
||||
|
@ -72,8 +77,11 @@ function unpackQuestionLabels(opts) {
|
|||
if (!labelLen) {
|
||||
break;
|
||||
}
|
||||
if (192 === labelLen) {
|
||||
var pointer = dv.getUint8(total, false);
|
||||
if (labelLen >= 0xc0) {
|
||||
// (11 000000 & whatever) signifies pointer
|
||||
// (00 111111 & whatever) bitmask for potentially large pointer
|
||||
// (00 000001 11111111) largest realistic pointer value (512 byte message size)
|
||||
var pointer = ((labelLen & 0x3f) << 8) | dv.getUint8(total, false);
|
||||
console.log('Found a pointer to'
|
||||
+ ' 0x' + pointer.toString(16) + ' (' + pointer + ')'
|
||||
+ ' at byte index'
|
||||
|
|
|
@ -26,11 +26,16 @@ exports.DNS_UNPACK_LABELS = function (ui8, ptr, q) {
|
|||
len = ui8[total];
|
||||
if (len === undefined){
|
||||
// RDATA is terminated by undefined, not len === 0
|
||||
q.trunc = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// Handle message compression pointers. See 4.1.4 of RFC1035 for details.
|
||||
// 0xc0 // 192 // parseInt('11000000', 2).toString(16)
|
||||
if (len >= 0xc0) {
|
||||
// Only the two highest bits are used to signify the pointer.
|
||||
// The remaining bits may be used to specify the address of the pointer
|
||||
// (it would seem that only 1 extra bit is actually used since the message size is 512 bytes)
|
||||
var cpptr = ((ui8[total] & 0x3f) << 8) | ui8[total + 1];
|
||||
|
||||
// We're not coming back, so if this is the first time we're following one of
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
(function (exports) {
|
||||
'use strict';
|
||||
|
||||
// FORMAT:
|
||||
// name ttl class rr name
|
||||
// foo. 15 IN NS www.example.com.
|
||||
|
||||
// Comes in variable lengths. It is the name of the primary Master for the Domain.
|
||||
// For example 'ns1.example.com'
|
||||
// It may be a label, pointer or any combination
|
||||
|
@ -8,11 +12,12 @@ var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js
|
|||
|
||||
|
||||
exports.DNS_PARSER_TYPE_NS = function (ab , packet, record) {
|
||||
record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
||||
return record;
|
||||
|
||||
var labelInfo = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' });
|
||||
if (record.trunc) {
|
||||
throw new Error("RDATA type NS must be `null`-terminated, not truncated by rdata length.");
|
||||
}
|
||||
record.data = labelInfo.name;
|
||||
return record;
|
||||
};
|
||||
|
||||
}('undefined' !== typeof window ? window : exports));
|
||||
|
||||
|
||||
|
|
|
@ -6,12 +6,16 @@
|
|||
// to a host name.
|
||||
|
||||
// FORMAT:
|
||||
// ame ttl class rr name
|
||||
// 15 IN PTR www.example.com.
|
||||
// name ttl class rr name
|
||||
// foo. 15 IN PTR www.example.com.
|
||||
|
||||
var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
|
||||
exports.DNS_PARSER_TYPE_PTR = function (ab, pack, record) {
|
||||
record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
||||
return record;
|
||||
var labelInfo = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' });
|
||||
if (record.trunc) {
|
||||
throw new Error("RDATA type PTR must be `null`-terminated, not truncated by rdata length.");
|
||||
}
|
||||
record.data = labelInfo.name;
|
||||
};
|
||||
|
||||
}('undefined' !== typeof window ? window : exports));
|
||||
|
|
Loading…
Reference in New Issue