Hello Bill,

Great ! You have found my bug !

My bad, I was  not aware of this difference between strncpy() and memcpy(. What's more I did not debuged it correctly ...

I just add below the code to clarify the BUG and the FIX (may be other people have this bug in there module and did not see the issue because they never have to get mac address starting by 00)

    case PHYSADDRESS: {
        if (get_field_ifTable_data(indexGpon_g , PHYSADDRESS) != NULL) {
            // strncpy (phy_address, get_field_ifTable_data(indexGpon_g , PHYSADDRESS), sizeof(phy_address));   // The BUG with strncpy             memcpy (phy_address, get_field_ifTable_data(indexGpon_g , PHYSADDRESS), sizeof(phy_address));       // The FIX with memcpy
            *var_len = 6;
        } else
            *var_len = 0;
        long_ret = *phy_address;
    } return (u_char *) phy_address;

Thanks a lot Bill !

Best Regards,

Damien GARCIA


Le 21/01/2021 à 17:37, Bill Fenner a écrit :
It's hard to say without seeing your code, but a common source of problems like this is using functions that are meant for nul-terminated strings (e.g., strncpy() ) instead of those meant for moving bytes around (e.g., memcpy() ).

  Bill


On Fri, Jan 15, 2021 at 10:06 AM dga via Net-snmp-coders <net-snmp-coders@lists.sourceforge.net <mailto:net-snmp-coders@lists.sourceforge.net>> wrote:

    Hello,

    I would like to add more details to clarify the problem.

    The 6 fields of mac address are returned to the agent under a
    string of
    6 chars: (let's say mac[6])

    So for the following mac address : "00:48:65:6C:6C:6F" :

    "00" => "NULL" = mac[0]

    "48" => "H" = mac[1]

    "65" => "e" = mac[2]

    "6C" => "l" = mac[3]

    "6C" => "l" = mac[4]

    "6F" => "o" = mac[5]

    it means we have : mac[6] = { '\0', 'H', 'e', 'l', 'l', 'o' , '\0'}

    This string (mac[6]) is returned with an other parameter (size_t *
    var_len) to giving the size of the string.  Here the size is 6 of
    course.

    But, when I get the corresponding oid value I get : "Hex-STRING:
    00 00
    00 00 00 00"

    It seems to be a bug ...

    Best Regards,

    Damien GARCIA


    Le 11/01/2021 à 20:27, dga a écrit :
    > Hello,
    >
    > I have written an snmp module to include additional interfaces
    in the
    > mib2 interface. However I face an issue with the field
    "ifPhysAddress"
    > (mac address) if the mac address of the interface starts by "00"
    > (example: "00:06:91:C6:B1:3F"). In that case I get "Hex-STRING:
    00 00
    > 00 00 00 00" instead of getting  "Hex-STRING: 00 06 91 C6 B1 3F"
    . Is
    > it a bug ?
    >
    > I have no issue with my module if the mac address that does NOT
    start
    > by "00".
    >
    > There is also no issue get mac address starting by "00" for the
    > default interfaces of the snmp demon.
    >
    >
    > May be someone has ever face the same issue ? Any help would be
    > greatly appreciated !
    >
    >
    > Best Regards,
    >
    > Damien GARCIA
    >
    >


    _______________________________________________
    Net-snmp-coders mailing list
    Net-snmp-coders@lists.sourceforge.net
    <mailto:Net-snmp-coders@lists.sourceforge.net>
    https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to