p11-glue / p11-kit

Provides a way to load and enumerate PKCS#11 modules.
https://p11-glue.github.io/p11-glue/p11-kit.html
Other
149 stars 91 forks source link

Build failure with stricter C compilers (e.g. GCC 14) #608

Closed thesamesam closed 8 months ago

thesamesam commented 9 months ago

Modern C compilers are becoming stricter with a variety of changes over the last year or so.

GCC 14 in particular (to be released in ~April 2024) fails to build p11-kit-0.25.3 like:

FAILED: p11-kit/p11-kit.p/import-object.c.o
x86_64-pc-linux-gnu-gcc -m32 -mfpmath=sse -Ip11-kit/p11-kit.p -Ip11-kit -I../p11-kit-0.25.3/p11-kit -I. -I../p11-kit-0.25.3 -Icommon -I../p11-kit-0.25.3/common -I/usr/lib/libffi/include -fdiagnostics-color=al
ways -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -D_GNU_SOURCE -DP11_KIT_FUTURE_UNSTABLE_API -O2 -pipe -march=native -fdiagnostics-color=always '-DBINDIR="/usr/bin"' '-DPRIVATEDIR="/usr/libexec/p11-kit"' '-DSY
SCONFDIR="/etc"' '-DP11_SYSTEM_CONFIG_FILE="/etc/pkcs11/pkcs11.conf"' '-DP11_SYSTEM_CONFIG_MODULES="/etc/pkcs11/modules"' '-DP11_PACKAGE_CONFIG_MODULES="/usr/share/p11-kit/modules"' '-DP11_USER_CONFIG_FILE="~
/.config/pkcs11/pkcs11.conf"' '-DP11_USER_CONFIG_MODULES="~/.config/pkcs11/modules"' '-DP11_MODULE_PATH="/usr/lib/pkcs11"' -MD -MQ p11-kit/p11-kit.p/import-object.c.o -MF p11-kit/p11-kit.p/import-object.c.o.d
 -o p11-kit/p11-kit.p/import-object.c.o -c ../p11-kit-0.25.3/p11-kit/import-object.c
../p11-kit-0.25.3/p11-kit/import-object.c: In function ‘add_attrs_pubkey_rsa’:
../p11-kit-0.25.3/p11-kit/import-object.c:223:62: error: passing argument 3 of ‘p11_asn1_read’ from incompatible pointer type [-Wincompatible-pointer-types]
  223 |         attr_modulus.pValue = p11_asn1_read (asn, "modulus", &attr_modulus.ulValueLen);
      |                                                              ^~~~~~~~~~~~~~~~~~~~~~~~
      |                                                              |
      |                                                              long unsigned int *
In file included from ../p11-kit-0.25.3/p11-kit/import-object.c:53:
../p11-kit-0.25.3/common/asn1.h:60:62: note: expected ‘size_t *’ {aka ‘unsigned int *’} but argument is of type ‘long unsigned int *’
   60 |                                                      size_t *length);
      |                                                      ~~~~~~~~^~~~~~
../p11-kit-0.25.3/p11-kit/import-object.c:229:70: error: passing argument 3 of ‘p11_asn1_read’ from incompatible pointer type [-Wincompatible-pointer-types]
  229 |         attr_exponent.pValue = p11_asn1_read (asn, "publicExponent", &attr_exponent.ulValueLen);
      |                                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                      |
      |                                                                      long unsigned int *
../p11-kit-0.25.3/common/asn1.h:60:62: note: expected ‘size_t *’ {aka ‘unsigned int *’} but argument is of type ‘long unsigned int *’
   60 |                                                      size_t *length);
      |                                                      ~~~~~~~~^~~~~~
../p11-kit-0.25.3/p11-kit/import-object.c: In function ‘add_attrs_pubkey_ec’:
../p11-kit-0.25.3/p11-kit/import-object.c:264:78: error: passing argument 3 of ‘p11_asn1_read’ from incompatible pointer type [-Wincompatible-pointer-types]
  264 |         attr_ec_params.pValue = p11_asn1_read (info, "algorithm.parameters", &attr_ec_params.ulValueLen);
      |                                                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                              |
      |                                                                              long unsigned int *
../p11-kit-0.25.3/common/asn1.h:60:62: note: expected ‘size_t *’ {aka ‘unsigned int *’} but argument is of type ‘long unsigned int *’
   60 |                                                      size_t *length);
      |                                                      ~~~~~~~~^~~~~~

Originally reported downstream in Gentoo at https://bugs.gentoo.org/918982.

This can be emulated with -Werror=incompatible-pointer-types -Werror=implicit -Werror=int-conversion on an older GCC or Clang.

ueno commented 9 months ago

Thanks for the report; #609 should fix it. I guess we should enable 32-bit build in our CI to catch this kind of problems.

thesamesam commented 8 months ago

Thank you! Yeah, that's a good idea. I haven't looked at your CI setup but I can look at doing that if you need me to.

The patch works for me, the quick response is really appreciated as going through quite a few of these.