markabrahams / node-net-snmp

JavaScript implementation of the Simple Network Management Protocol (SNMP)
209 stars 97 forks source link

session.subtree: feedCallback return value not checked (version 3.9.7) #240

Closed christopher-nielsen-ny closed 9 months ago

christopher-nielsen-ny commented 10 months ago

The current implementation for session.subtree() doesn't appear to check the return value of feedCallback, preventing user code from avoiding further calls. That's easily reproduced with a callback that returns true. It's also immediately clear from the node-net-snmp code in question:

function subtreeCb (req, varbinds) {
    var done = 0;

    for (var i = varbinds.length; i > 0; i--) {
        if (! oidInSubtree (req.baseOid, varbinds[i - 1].oid)) {
            done = 1;
            varbinds.pop ();
        }
    }

    if (varbinds.length > 0)
        // BUG: START: This code is incomplete: If feedCb return value is true, 'done' should be set to 1
        req.feedCb (varbinds);
        // BUG: END

    if (done)
        return true;
}

The fix is trivial, and might look like the following (to be consistent with other node-net-snmp code):

[...]
    if (varbinds.length > 0) {
        if (req.feedCb (varbinds)) {
            done = 1;
        }
    }
[...]

While very trivial, I'd be happy to submit a PR if it would help. Please let me know either way.

markabrahams commented 9 months ago

Hi @christopher-nielsen-ny - thanks for raising this and for the PR. I'll merge this shortly.

markabrahams commented 9 months ago

I've just merged #242 to fix this, and published in version 3.9.8 of the npm.

christopher-nielsen-ny commented 9 months ago

I've just merged #242 to fix this, and published in version 3.9.8 of the npm.

Great, thank you so much Mark!