markabrahams / node-net-snmp

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

Invalid check of ObjectType.IpAddress in agent castSetValue #211

Closed meydanb closed 1 year ago

meydanb commented 1 year ago

When the agent receives a set request for a variable of type IpAddress there is a wrong check that causes the agent to throw an "Invalid IP Address" exception, even though a valid ip address was supplied.

The issue originates in the castSetValue function. it seems that there is a check on the length of the value that was received (as a string), rather than checking the number of actual octets:

case ObjectType.IpAddress:
        // A 32-bit internet address represented as OCTET STRING of length 4
        if ( typeof value != "string" || value.length != 4 ) {
            throw new Error("Invalid IpAddress", value);
        }
        return value;
markabrahams commented 1 year ago

Hi @meydanb - thanks for that! I've merged #212 and published this in version 3.8.4 of the npm.

meydanb commented 1 year ago

Thank you @markabrahams, this is a such useful library. keep up the good work!

markabrahams commented 1 year ago

Great to hear that you're finding it useful!