mafintosh / dns-packet

An abstract-encoding compliant module for encoding / decoding DNS packets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TXT records can no longer have empty text

johan13 opened this issue · comments

Starting with commit f6db3d3, I can no longer send TXT records with an empty payload using multicast-dns:

{name, type: "TXT", ttl, data: ""}

I have identified the problem to be the coalescing of data and options on line 1241 of dns-packet:

return name.encodingLength(a.name) + 8 + renc(a.type).encodingLength(a.data || a.options)

Would it be possible to change that into a comparison with null and/or undefined instead to allow empty TXT records again? Sending empty TXT records may seem pointless, but I found it to be required for interoperability with certain mDNS clients.

I found a workaround by passing Buffer.alloc(0) instead of "", but maybe it'd be nice to get this fixed anyway?

Edit: Nevermind, I see the issue.

That looks good, but I get a TypeError when I run the same code:

$ git clone https://github.com/mafintosh/dns-packet.git ; cd dns-packet ; npm i ; node -e "require('.').encode({type: 'response', answers: [{name: '.', type: 'TXT',data: ''}]})"
Cloning into 'dns-packet'...
remote: Counting objects: 301, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 301 (delta 10), reused 17 (delta 6), pack-reused 279
Receiving objects: 100% (301/301), 112.83 KiB | 560.00 KiB/s, done.
Resolving deltas: 100% (171/171), done.
npm notice created a lockfile as package-lock.json. You should commit this file.
added 202 packages in 3.991s
/Users/jlevin/Projects/dns-packet/index.js:350
      length += buf.length + 1
                    ^

TypeError: Cannot read property 'length' of undefined
    at /Users/jlevin/Projects/dns-packet/index.js:350:21
    at Array.forEach (<anonymous>)
    at Object.rtxt.encodingLength (/Users/jlevin/Projects/dns-packet/index.js:346:8)
    at Object.answer.encodingLength (/Users/jlevin/Projects/dns-packet/index.js:1241:57)
    at encodingLengthList (/Users/jlevin/Projects/dns-packet/index.js:1382:52)
    at Object.exports.encodingLength (/Users/jlevin/Projects/dns-packet/index.js:1351:5)
    at Object.exports.encode (/Users/jlevin/Projects/dns-packet/index.js:1304:46)
    at [eval]:1:14
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at Object.runInThisContext (vm.js:139:38)

I run this on a Mac with Node 8:

$ node -p process.versions
{ http_parser: '2.8.0',
  node: '8.11.3',
  v8: '6.2.414.54',
  uv: '1.19.1',
  zlib: '1.2.11',
  ares: '1.10.1-DEV',
  modules: '57',
  nghttp2: '1.32.0',
  napi: '3',
  openssl: '1.0.2o',
  icu: '62.1',
  unicode: '11.0',
  cldr: '33.1',
  tz: '2018e' }

Yeah, I was actually playing around earlier with a fix, so I didn't notice. Fixed in dns-packet@5.0.1.

👍 Thank you!