mafintosh / dns-packet

An abstract-encoding compliant module for encoding / decoding DNS packets
MIT License
205 stars 71 forks source link

Make name.decode stricter #79

Closed jviide closed 2 years ago

jviide commented 2 years ago

This pull request makes the name.decode function to be stricter about what kind of data it accepts:

This pull request also adds tests aimed to catch these cases.

Without to these checks it's possible to craft packets that take advantage of name.decode to cause Node.js to run out of memory when processing a ~60 kilobyte packet that takes advantage of infinite pointer loops and unlimited name lengths:

const packet = require("dns-packet");

const buf = Buffer.alloc(65500);
buf.set([
  0xbe, 0xef, 0x85, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]);
buf.fill(Buffer.from([0x01, 0x00]), 12);
buf.writeUInt16BE(0xc00c, buf.length - 2);

packet.decode(buf);

Just for full disclosure: Prior to making this pull request I confirmed from @mafintosh over Twitter DMs whether it's okay to submit this PR publicly šŸ™‚

mafintosh commented 2 years ago

Thanks for the fix! Do you mind fixing my nit, then it's good to go.

jviide commented 2 years ago

Changed "Can't" to "Cannot" šŸ‘

mafintosh commented 2 years ago

5.3.1