delian / node-netflowv9

NetFlow Version 9 library for Node.JS
GNU General Public License v2.0
42 stars 13 forks source link

Handle undefined list #21

Closed gavinaiken closed 5 years ago

gavinaiken commented 5 years ago

This fixes a situation where the code throws an error like this:

node_modules/node-netflowv9/js/nf9/nf9decode.js:50
        for (i = 0, n = 0; i < list.length; i++, n += z.len) {
                                    ^
TypeError: Cannot read property 'length' of undefined
    at compileTemplate (node_modules/node-netflowv9/js/nf9/nf9decode.js:50:37)
    at decodeTemplate (node_modules/node-netflowv9/js/nf9/nf9decode.js:89:40)
    at NetFlowV9.nf9PktDecode (node_modules/node-netflowv9/js/nf9/nf9decode.js:171:32)
    at NetFlowV9.nfPktDecode (node_modules/node-netflowv9/netflowv9.js:33:25)
    at Immediate.NetFlowV9.fetch (node_modules/node-netflowv9/netflowv9.js:139:24)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)

This happened when I have a template object with a len property but no compiled or list property. Looking through the code I couldn't see where a template could get added without either of those, so I patched it by handling the undefined list.