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

Address comparison warnings (-> errors) when compiling with GCC 13.2 #246

Closed
Niautanor opened this issue May 31, 2024 · 1 comment
Closed
Assignees
Labels
support User support

Comments

@Niautanor
Copy link
Contributor

I get the following warnings (which escalate to errors due to -Werror) when building with GCC 13.2

[1/3] Building C object src/CMakeFiles/crypto.dir/core/crypto_mc.c.o
FAILED: src/CMakeFiles/crypto.dir/core/crypto_mc.c.o 
/usr/bin/cc -Dcrypto_EXPORTS -I/home/luna/git/CryptoLib/include -I/home/luna/git/CryptoLib/src/../include -Wall -Wextra -Werror -g -O0 -g -fPIC -MD -MT src/CMakeFiles/crypto.dir/core/crypto_mc.c.o -MF src/CMakeFiles/crypto.dir/core/crypto_mc.c.o.d -o src/CMakeFiles/crypto.dir/core/crypto_mc.c.o -c /home/luna/git/CryptoLib/src/core/crypto_mc.c
/home/luna/git/CryptoLib/src/core/crypto_mc.c: In function ‘Crypto_SA_readARSN’:
/home/luna/git/CryptoLib/src/core/crypto_mc.c:212:27: error: the comparison will always evaluate as ‘false’ for the address of ‘iv’ will never be NULL [-Werror=address]
  212 |             if(sa_ptr->iv == NULL)
      |                           ^~
In file included from /home/luna/git/CryptoLib/include/crypto_print.h:26,
                 from /home/luna/git/CryptoLib/include/crypto.h:38,
                 from /home/luna/git/CryptoLib/src/core/crypto_mc.c:22:
/home/luna/git/CryptoLib/include/crypto_structs.h:71:13: note: ‘iv’ declared here
   71 |     uint8_t iv[IV_SIZE];    // Initialization Vector
      |             ^~
cc1: all warnings being treated as errors
[2/3] Building C object src/CMakeFiles/crypto.dir/sa/internal/sa_interface_inmemory.template.c.o
FAILED: src/CMakeFiles/crypto.dir/sa/internal/sa_interface_inmemory.template.c.o 
/usr/bin/cc -Dcrypto_EXPORTS -I/home/luna/git/CryptoLib/include -I/home/luna/git/CryptoLib/src/../include -Wall -Wextra -Werror -g -O0 -g -fPIC -MD -MT src/CMakeFiles/crypto.dir/sa/internal/sa_interface_inmemory.template.c.o -MF src/CMakeFiles/crypto.dir/sa/internal/sa_interface_inmemory.template.c.o.d -o src/CMakeFiles/crypto.dir/sa/internal/sa_interface_inmemory.template.c.o -c /home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c: In function ‘sa_get_from_spi’:
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c:438:12: error: the comparison will always evaluate as ‘false’ for the address of ‘sa’ will never be NULL [-Werror=address]
  438 |     if (sa == NULL)
      |            ^~
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c:41:30: note: ‘sa’ declared here
   41 | static SecurityAssociation_t sa[NUM_SA];
      |                              ^~
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c:443:20: error: the comparison will always evaluate as ‘false’ for the address of ‘iv’ will never be NULL [-Werror=address]
  443 |     if (sa[spi].iv == NULL && (sa[spi].shivf_len > 0) && crypto_config.cryptography_type != CRYPTOGRAPHY_TYPE_KMCCRYPTO)
      |                    ^~
In file included from /home/luna/git/CryptoLib/include/crypto_print.h:26,
                 from /home/luna/git/CryptoLib/include/crypto.h:38,
                 from /home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c:15:
/home/luna/git/CryptoLib/include/crypto_structs.h:71:13: note: ‘iv’ declared here
   71 |     uint8_t iv[IV_SIZE];    // Initialization Vector
      |             ^~
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c:447:21: error: the comparison will always evaluate as ‘false’ for the address of ‘abm’ will never be NULL [-Werror=address]
  447 |     if (sa[spi].abm == NULL && sa[spi].ast)
      |                     ^~
/home/luna/git/CryptoLib/include/crypto_structs.h:76:13: note: ‘abm’ declared here
   76 |     uint8_t abm[ABM_SIZE];  // Authentication Bit Mask (Primary Hdr. through Security Hdr.)
      |             ^~~
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c: In function ‘sa_get_operational_sa_from_gvcid_find_iv’:
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c:476:26: error: the comparison will always evaluate as ‘false’ for the address of ‘iv’ will never be NULL [-Werror=address]
  476 |             if (sa[i].iv == NULL && (sa[i].ast == 1 || sa[i].est == 1) && crypto_config.cryptography_type != CRYPTOGRAPHY_TYPE_KMCCRYPTO)
      |                          ^~
/home/luna/git/CryptoLib/include/crypto_structs.h:71:13: note: ‘iv’ declared here
   71 |     uint8_t iv[IV_SIZE];    // Initialization Vector
      |             ^~
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c:482:27: error: the comparison will always evaluate as ‘false’ for the address of ‘abm’ will never be NULL [-Werror=address]
  482 |             if (sa[i].abm == NULL && sa[i].ast)
      |                           ^~
/home/luna/git/CryptoLib/include/crypto_structs.h:76:13: note: ‘abm’ declared here
   76 |     uint8_t abm[ABM_SIZE];  // Authentication Bit Mask (Primary Hdr. through Security Hdr.)
      |             ^~~
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c: In function ‘sa_get_operational_sa_from_gvcid’:
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c:663:12: error: the comparison will always evaluate as ‘false’ for the address of ‘sa’ will never be NULL [-Werror=address]
  663 |     if (sa == NULL)
      |            ^~
/home/luna/git/CryptoLib/src/sa/internal/sa_interface_inmemory.template.c:41:30: note: ‘sa’ declared here
   41 | static SecurityAssociation_t sa[NUM_SA];
      |                              ^~
cc1: all warnings being treated as errors

GCC is saying "Since sa is a statically allocated array the standard says that it's address is and always will be different from NULL.". I initially assumed these checks were added following a certain coding standard that requires all pointer accesses to be checked but e.g. key_interface_internal_template.c doesn't have them either so maybe they were intended to be meaningful (or are remnants from an old version where they were meaningful).

Please have a look if these checks still have some reason for being there that is currently unfulfilled (i.e. the intention of the if (sa) seems to be to check that sa_init() was called: maybe sa_init() should set some variable to indicate that that could be checked instead) or if they can be removed and I'll be happy to provide a merge request.

@jlucas9 jlucas9 added the support User support label Jun 3, 2024
@rjbrown2
Copy link
Contributor

rjbrown2 commented Jun 3, 2024

Thank you for bringing this to our attention. Many of these are no longer necessary. They are in the process of being removed.

Donnie-Ice added a commit that referenced this issue Jun 4, 2024
…ors-when-compiling-with-gcc-132

[#246] Fix GCC 13.x Compilation Issues with Null SA/IV
@rjbrown2 rjbrown2 closed this as completed Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support User support
Projects
None yet
Development

No branches or pull requests

4 participants