From 7bcaa2599365350dbaa48f882c79f3e5d38cbb17 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 8 Nov 2020 07:02:44 +0100 Subject: [PATCH 1/2] drivers/snmp-ups.c: comment about issue found by pedantic compiler snmp-ups.c: In function 'nut_snmp_init': snmp-ups.c:599:66: error: division 'sizeof (oid * {aka long unsigned int *}) / sizeof (oid {aka long unsigned int})' does not compute the number of array elements [-Werror=sizeof-pointer-div] 599 | g_snmp_sess.securityPrivProtoLen = sizeof(usmAESPrivProtocol)/sizeof(oid); | ^ In file included from /usr/include/net-snmp/snmpv3_api.h:27, from /usr/include/net-snmp/net-snmp-includes.h:78, from snmp-ups.h:79, from snmp-ups.c:39: /usr/include/net-snmp/library/transform_oids.h:50:26: note: first 'sizeof' operand was declared here 50 | NETSNMP_IMPORT oid *usmAES128PrivProtocol; /* backwards compat */ | ^~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[1]: *** [Makefile:1953: snmp_ups-snmp-ups.o] Error 1 --- drivers/snmp-ups.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/snmp-ups.c b/drivers/snmp-ups.c index 74b58c99ab..3c98f9df80 100644 --- a/drivers/snmp-ups.c +++ b/drivers/snmp-ups.c @@ -593,6 +593,9 @@ void nut_snmp_init(const char *type, const char *hostname) } else if (strcmp(privProtocol, "AES") == 0) { g_snmp_sess.securityPrivProto = usmAESPrivProtocol; + /* FIXME: Find another way to get the size of array(?) to avoid: + * error: division 'sizeof (oid * {aka long unsigned int *}) / sizeof (oid {aka long unsigned int})' does not compute the number of array elements [-Werror=sizeof-pointer-div] + */ g_snmp_sess.securityPrivProtoLen = sizeof(usmAESPrivProtocol)/sizeof(oid); } else From c7cf507454bcf6f40b24b58e61c130c7772c5bf2 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 15 Nov 2020 01:29:30 +0100 Subject: [PATCH 2/2] drivers/snmp-ups.c: fix the warning about how we get the size of usmAES128PrivProtocol --- drivers/snmp-ups.c | 24 +++++++++++++++++++----- m4/nut_check_libnetsnmp.m4 | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/drivers/snmp-ups.c b/drivers/snmp-ups.c index 3c98f9df80..c4a0fd5fc2 100644 --- a/drivers/snmp-ups.c +++ b/drivers/snmp-ups.c @@ -66,10 +66,27 @@ #include "hpe-pdu-mib.h" /* Address API change */ -#ifndef usmAESPrivProtocol +#if ( ! NUT_HAVE_LIBNETSNMP_usmAESPrivProtocol ) && ( ! defined usmAESPrivProtocol ) #define usmAESPrivProtocol usmAES128PrivProtocol #endif +#ifdef USM_PRIV_PROTO_AES_LEN +# define NUT_securityPrivProtoLen USM_PRIV_PROTO_AES_LEN +#else +# ifdef USM_PRIV_PROTO_AES128_LEN +# define NUT_securityPrivProtoLen USM_PRIV_PROTO_AES128_LEN +# else +/* FIXME: Find another way to get the size of array(?) to avoid: + * error: division 'sizeof (oid * {aka long unsigned int *}) / sizeof (oid {aka long unsigned int})' does not compute the number of array elements [-Werror=sizeof-pointer-div] + * See also https://bugs.php.net/bug.php?id=37564 for context + * which is due to most values in /usr/include/net-snmp/librarytransform_oids.h + * being defined as "oid[10]" or similar arrays, and "backwards compatibility" + * usmAESPrivProtocol name is an "oid *" pointer. + */ +# define NUT_securityPrivProtoLen (sizeof(usmAESPrivProtocol)/sizeof(oid)) +# endif +#endif + static mib2nut_info_t *mib2nut[] = { &apc, &mge, @@ -593,10 +610,7 @@ void nut_snmp_init(const char *type, const char *hostname) } else if (strcmp(privProtocol, "AES") == 0) { g_snmp_sess.securityPrivProto = usmAESPrivProtocol; - /* FIXME: Find another way to get the size of array(?) to avoid: - * error: division 'sizeof (oid * {aka long unsigned int *}) / sizeof (oid {aka long unsigned int})' does not compute the number of array elements [-Werror=sizeof-pointer-div] - */ - g_snmp_sess.securityPrivProtoLen = sizeof(usmAESPrivProtocol)/sizeof(oid); + g_snmp_sess.securityPrivProtoLen = NUT_securityPrivProtoLen; } else fatalx(EXIT_FAILURE, "Bad SNMPv3 authProtocol: %s", authProtocol); diff --git a/m4/nut_check_libnetsnmp.m4 b/m4/nut_check_libnetsnmp.m4 index 83b26330b7..06be25f3d3 100644 --- a/m4/nut_check_libnetsnmp.m4 +++ b/m4/nut_check_libnetsnmp.m4 @@ -75,6 +75,22 @@ if test -z "${nut_have_libnetsnmp_seen}"; then if test "${nut_have_libnetsnmp}" = "yes"; then LIBNETSNMP_CFLAGS="${CFLAGS}" LIBNETSNMP_LIBS="${LIBS}" + + AC_MSG_CHECKING([for defined usmAESPrivProtocol]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ +#include +#include +oid * pProto = usmAESPrivProtocol; +], +[] + )], + [AC_MSG_RESULT([yes]) + AC_DEFINE_UNQUOTED(NUT_HAVE_LIBNETSNMP_usmAESPrivProtocol, 1, [Variable or macro by this name is resolvable]) + ], + [AC_MSG_RESULT([no]) + AC_DEFINE_UNQUOTED(NUT_HAVE_LIBNETSNMP_usmAESPrivProtocol, 0, [Variable or macro by this name is not resolvable]) + ]) + fi dnl restore original CFLAGS and LIBS