more helpful error
This commit is contained in:
parent
92e85bead3
commit
8148e25d18
|
@ -58,11 +58,11 @@ pdns.unpack = function (ab) {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
|
||||||
var dv = new DataView(ab);
|
var dv = new DataView(ab);
|
||||||
var id = dv.getUint16(0, false);
|
var id = dv.getUint16(0, false);
|
||||||
packet.header = pdns.unpackHeader(dv.getUint16(2, false));
|
packet.header = pdns.unpackHeader(dv.getUint16(2, false));
|
||||||
var qdcount = dv.getUint16(4, false); // query count
|
packet.qdcount = dv.getUint16(4, false); // query count
|
||||||
var ancount = dv.getUint16(6, false); // answer count
|
packet.ancount = dv.getUint16(6, false); // answer count
|
||||||
var nscount = dv.getUint16(8, false); // authority count
|
packet.nscount = dv.getUint16(8, false); // authority count
|
||||||
var arcount = dv.getUint16(10, false); // additional count
|
packet.arcount = dv.getUint16(10, false); // additional count
|
||||||
var total = 12;
|
var total = 12;
|
||||||
var i;
|
var i;
|
||||||
var rec;
|
var rec;
|
||||||
|
@ -114,6 +114,7 @@ pdns.unpack = function (ab) {
|
||||||
|
|
||||||
function unpackAnswer(ab, dv, ui8, total) {
|
function unpackAnswer(ab, dv, ui8, total) {
|
||||||
var ototal = total;
|
var ototal = total;
|
||||||
|
var err;
|
||||||
var q = pdns._unpackLabels(ui8, total, {
|
var q = pdns._unpackLabels(ui8, total, {
|
||||||
name: ''
|
name: ''
|
||||||
, type: 0
|
, type: 0
|
||||||
|
@ -136,10 +137,15 @@ pdns.unpack = function (ab) {
|
||||||
|
|
||||||
if (ab.byteLength - total < 10) {
|
if (ab.byteLength - total < 10) {
|
||||||
// console.error(str.join(''));
|
// console.error(str.join(''));
|
||||||
throw new Error(
|
//console.error(JSON.stringify(packet, null, 1));
|
||||||
|
//console.error(JSON.stringify(q, null, 1));
|
||||||
|
err = new Error(
|
||||||
"Expected a 2-byte QTYPE, 2-byte QCLASS, 4-byte TTL, and 2-byte RDLENGTH following " + total + "-byte QNAME"
|
"Expected a 2-byte QTYPE, 2-byte QCLASS, 4-byte TTL, and 2-byte RDLENGTH following " + total + "-byte QNAME"
|
||||||
+ " but packet itself has " + (ab.byteLength - total) + " bytes remaining"
|
+ " but packet itself has " + (ab.byteLength - total) + " bytes remaining"
|
||||||
);
|
);
|
||||||
|
err.packet = packet;
|
||||||
|
err.record = q;
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
q.type = dv.getUint16(total, false);
|
q.type = dv.getUint16(total, false);
|
||||||
|
@ -171,33 +177,33 @@ pdns.unpack = function (ab) {
|
||||||
packet.header.id = id;
|
packet.header.id = id;
|
||||||
|
|
||||||
|
|
||||||
console.log('qdcount', qdcount);
|
console.log('qdcount', packet.qdcount);
|
||||||
packet.question = [];
|
packet.question = [];
|
||||||
for (i = 0; i < qdcount; i += 1) {
|
for (i = 0; i < packet.qdcount; i += 1) {
|
||||||
rec = unpackQuestion(ab, dv, ui8, total);
|
rec = unpackQuestion(ab, dv, ui8, total);
|
||||||
total += rec.byteLength;
|
total += rec.byteLength;
|
||||||
packet.question.push(rec);
|
packet.question.push(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('ancount', ancount);
|
console.log('ancount', packet.ancount);
|
||||||
packet.answer = [];
|
packet.answer = [];
|
||||||
for (i = 0; i < ancount; i += 1) {
|
for (i = 0; i < packet.ancount; i += 1) {
|
||||||
rec = unpackAnswer(ab, dv, ui8, total);
|
rec = unpackAnswer(ab, dv, ui8, total);
|
||||||
total += rec.byteLength;
|
total += rec.byteLength;
|
||||||
packet.answer.push(rec);
|
packet.answer.push(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('nscount', nscount);
|
console.log('nscount', packet.nscount);
|
||||||
packet.authority = [];
|
packet.authority = [];
|
||||||
for (i = 0; i < nscount; i += 1) {
|
for (i = 0; i < packet.nscount; i += 1) {
|
||||||
rec = unpackAnswer(ab, dv, ui8, total);
|
rec = unpackAnswer(ab, dv, ui8, total);
|
||||||
total += rec.byteLength;
|
total += rec.byteLength;
|
||||||
packet.authority.push(rec);
|
packet.authority.push(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('arcount', arcount);
|
console.log('arcount', packet.arcount);
|
||||||
packet.additional = [];
|
packet.additional = [];
|
||||||
for (i = 0; i < arcount; i += 1) {
|
for (i = 0; i < packet.arcount; i += 1) {
|
||||||
rec = unpackAnswer(ab, dv, ui8, total);
|
rec = unpackAnswer(ab, dv, ui8, total);
|
||||||
total += rec.byteLength;
|
total += rec.byteLength;
|
||||||
packet.additional.push(rec);
|
packet.additional.push(rec);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var dnsjs = require('../').DNSPacket;
|
var dnsjs = require('../').DNSPacket;
|
||||||
var expected; // shim
|
var expected; // shim
|
||||||
|
var onefile = process.argv[2];
|
||||||
|
|
||||||
var dirname = path.join(__dirname, 'fixtures');
|
var dirname = path.join(__dirname, 'fixtures');
|
||||||
|
|
||||||
|
@ -42,6 +43,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readdirSync(dirname).forEach(function (name) {
|
fs.readdirSync(dirname).forEach(function (name) {
|
||||||
|
if (onefile && !onefile.split(',').some(function (f) { return name.match(onefile); })) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!/\.bin$/.test(name)) {
|
if (!/\.bin$/.test(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -58,8 +62,11 @@
|
||||||
try {
|
try {
|
||||||
result = dnsjs.parse(ab);
|
result = dnsjs.parse(ab);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
console.error('[Error] parse error');
|
||||||
console.log(ab);
|
console.log(ab);
|
||||||
console.error('[Error] ' + e.message);
|
console.error(e.packet);
|
||||||
|
console.error(e.record);
|
||||||
|
console.error(e.stack);
|
||||||
console.error('');
|
console.error('');
|
||||||
//console.error(e.stack);
|
//console.error(e.stack);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue