Re: Net-SNMP 5.10.pre1 released for testing

Bart Van Assche via Net-snmp-coders <[email protected]> Mon, 10 Mar 2025 09:02:29 -0700
Newsgroups gmane.network.net-snmp.devel
Message-ID <[email protected]>
On 3/10/25 4:27 AM, Stuart Henderson wrote:
> To see how things are going with API changes, I've tested building
> everything in OpenBSD ports which depends on this. (I'm not suggesting
> that Net-SNMP needs to change anything unless these are unexpected, but
> at least giving other package maintainers a heads-up on what might be
> affected).

Thank you for having done this before Net-SNMP version 5.10 is released.

> gnugk:
> 
> snmp.cxx:87:11: error: expected '(' for function-style cast or type construction
>          trapOID[ OID_LENGTH(trapOID) - 1 ] = trapNumber;
>                   ^~~~~~~~~~~~~~~~~~~
> /usr/local/include/net-snmp/library/asn1.h:65:56: note: expanded from macro 'OID_LENGTH'
>       sizeof(int[-__builtin_types_compatible_p(typeof(x), typeof(&(x)[0]))]))
>                                                ~~~~~~~~~^
> snmp.cxx:87:11: error: expected '(' for function-style cast or type construction
>          trapOID[ OID_LENGTH(trapOID) - 1 ] = trapNumber;
                    ^~~~~~~~~~~~~~~~~~~

What compiler and flags have been selected by the configure script of
gnugk? Use of __builtin_types_compatible_p() is guarded as follows in
the Net-SNMP headers:

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define OID_LENGTH(x)                                                   \
     (sizeof(x) / sizeof((x)[0]) +                                       \
      sizeof(int[-__builtin_types_compatible_p(typeof(x), 
typeof(&(x)[0]))]))
#else
#define OID_LENGTH(x)  (sizeof(x) / sizeof((x)[0]))
#endif

> ntopng:
> various from snmp_sess_* functions taking struct session_list * rather
> than void *, and also

Unless anyone objects, I will look into modifying these functions such
that these accept a void * pointer again.

> src/SNMP.cpp:452:47: error: assigning to 'oid *' (aka 'unsigned long *') from incompatible type 'const oid[10]' (aka 'const unsigned long[10]')
>              snmpSession->session.securityAuthProto = usmHMACMD5AuthProtocol;
>                                                       ^~~~~~~~~~~~~~~~~~~~~~

The above error indicates a potential memory corruption issue in ntopng.
Any pointer assigned to snmpSession->session.securityAuthProto should
point at dynamically allocated memory and not to a static array. The
code for freeing session->securityAuthProto in snmplib/snmp_api.c is 26
years old if I interpret the git history correctly.

Bart.