Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/snmp-ups.c: usmAESPrivProtocol is not an array to properly use a sizeof() #850

Merged
merged 3 commits into from
Nov 15, 2020

Conversation

jimklimov
Copy link
Member

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

In my recent fight against warnings in NUT codebase, augmented by #844 and following from #823, this issue remains the only one I don't have an idea about solving. Help would be very much welcome to make a lot of additional Travis CI test-cases green.

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
@lgtm-com
Copy link

lgtm-com bot commented Nov 8, 2020

This pull request introduces 1 alert when merging 7bcaa25 into 8c1ad08 - view on LGTM.com

new alerts:

  • 1 for FIXME comment

@jimklimov jimklimov mentioned this pull request Nov 8, 2020
@jimklimov jimklimov changed the title drivers/snmp-ups.c: comment about issue found by pedantic compiler [HELP NEEDED] drivers/snmp-ups.c: comment about issue found by pedantic compiler Nov 8, 2020
@lgtm-com
Copy link

lgtm-com bot commented Nov 15, 2020

This pull request introduces 1 alert when merging c7cf507 into 3f9225d - view on LGTM.com

new alerts:

  • 1 for FIXME comment

@lgtm-com
Copy link

lgtm-com bot commented Nov 15, 2020

This pull request introduces 1 alert when merging f8667a4 into e65acaa - view on LGTM.com

new alerts:

  • 1 for FIXME comment

@jimklimov jimklimov changed the title [HELP NEEDED] drivers/snmp-ups.c: comment about issue found by pedantic compiler drivers/snmp-ups.c: comment about issue found by pedantic compiler Nov 15, 2020
@jimklimov
Copy link
Member Author

Some investigation showed that the token we use is defined in current net-snmp headers as a legacy pointer type, oid *, while many other names in the same header are arrays typed like oid[10]. There are also named macros to represent the amount of entries in those arrays, which is what we would use as a priority if available.

@jimklimov jimklimov changed the title drivers/snmp-ups.c: comment about issue found by pedantic compiler drivers/snmp-ups.c: usmAESPrivProtocol is not an array to properly use a sizeof() Nov 15, 2020
@jimklimov jimklimov merged commit fc4b29a into networkupstools:master Nov 15, 2020
@jimklimov jimklimov deleted the fightwarn-snmpups-aes branch November 15, 2020 10:26
@Bi11
Copy link
Contributor

Bi11 commented Dec 9, 2020

It is more than a warning. Because incorrect length of usmAES128PrivProtocol, generate_Ku fails and AES doesn't work.
The similar issue is affecting nut-scanner too.

See #734 (comment)

@jimklimov
Copy link
Member Author

Hell @Bi11 and sorry for the delay. I've read through this and linked comments, and my understanding is that with the current state of the master branch (or at least with these fixes applied to your build) AES works for you, while in the (aged) 2.7.4 release it did not?

Can you clarify please if there remains something to fix in nut-scanner along the same lines, or is it also already fixed? In the past weeks I juggled almost a thousand commits to fix warnings here and there, and lost track a bit :) So verifications like this are very welcome, whatever the verdict ;)

@Bi11
Copy link
Contributor

Bi11 commented Dec 12, 2020

I've just tried the master branch, the "sizeof" issue in 2.7.4 has been fixed with your commits, both in drivers/snmp-ups and nut-scanner. I'm really appreciated for your improvements made to this project, @jimklimov.

However, nut-scanner is still not working with my UPS, and there are some other trivial issues. I'll create a new Issue or PR once I make it work with my UPS.

@jimklimov
Copy link
Member Author

jimklimov commented Dec 12, 2020 via email

@clepple clepple added the SNMP label Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants