stefanberger / libtpms

The libtpms library provides software emulation of a Trusted Platform Module (TPM 1.2 and TPM 2.0)
Other
219 stars 95 forks source link

Warning nvHandle may be used uninitialised with gcc 10 #133

Closed michaelweiser closed 4 years ago

michaelweiser commented 4 years ago

With gcc 10.1.0 I get with current master:

bin/sh ../libtool  --tag=CC   --mode=compile x86_64-pc-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I..    -include tpm_library_conf.h -I../include/libtpms -I../include/libtpms -fstack-protector-strong    -D_POSIX_ -DTPM_POSIX -DTPM_LIBTPMS_CALLBACKS -I ./tpm2 -I ./tpm2/crypto -I ./tpm2/crypto/openssl -g -O2 -DUSE_OPENSSL_FUNCTIONS_SYMMETRIC=1 -DUSE_OPENSSL_FUNCTIONS_EC=1 -DUSE_OPENSSL_FUNCTIONS_ECDSA=1 -DUSE_OPENSSL_FUNCTIONS_RSA=1  -Wall -Werror -Wreturn-type -Wsign-compare -Wno-self-assign -c -o tpm2/libtpms_tpm2_la-NVDynamic.lo `test -f 'tpm2/NVDynamic.c' || echo './'`tpm2/NVDynamic.c
libtool: compile:  x86_64-pc-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I.. -include tpm_library_conf.h -I../include/libtpms -I../include/libtpms -fstack-protector-strong -D_POSIX_ -DTPM_POSIX -DTPM_LIBTPMS_CALLBACKS -I ./tpm2 -I ./tpm2/crypto -I ./tpm2/crypto/openssl -g -O2 -DUSE_OPENSSL_FUNCTIONS_SYMMETRIC=1 -DUSE_OPENSSL_FUNCTIONS_EC=1 -DUSE_OPENSSL_FUNCTIONS_ECDSA=1 -DUSE_OPENSSL_FUNCTIONS_RSA=1 -Wall -Werror -Wreturn-type -Wsign-compare -Wno-self-assign -c tpm2/NVDynamic.c  -fPIC -DPIC -o tpm2/.libs/libtpms_tpm2_la-NVDynamic.o
tpm2/NVDynamic.c: In function ‘NvNextByType’:
tpm2/NVDynamic.c:126:10: error: ‘nvHandle’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  126 |  *handle = nvHandle;
      |  ~~~~~~~~^~~~~~~~~~
tpm2/NVDynamic.c: At top level:
cc1: note: unrecognized command-line option ‘-Wno-self-assign’ may have been intended to silence earlier diagnostics
cc1: all warnings being treated as errors
make[2]: *** [Makefile:2583: tpm2/libtpms_tpm2_la-NVDynamic.lo] Error 1

The following change silences the warning but I'm unsure if it's semantically correct:

diff --git a/src/tpm2/NVDynamic.c b/src/tpm2/NVDynamic.c
index 32f46bb..c51233e 100644
--- a/src/tpm2/NVDynamic.c
+++ b/src/tpm2/NVDynamic.c
@@ -114,7 +114,7 @@ NvNextByType(
             )
 {
     NV_REF           addr;
-    TPM_HANDLE       nvHandle;
+    TPM_HANDLE       nvHandle = 0;
     while((addr = NvNext(iter, &nvHandle)) != 0)
        {
            // addr: the address of the location containing the handle of the value
stefanberger commented 4 years ago

gcc again... Thanks for reporting this. I'll have a look at it.

Do you happen to know whether this also occurs with the stable-0.6.0 and stable-0.7.0 branches?

salahcoronya commented 4 years ago

Yes, it does (I needed to cherry-pick 0d22a7aea2eb0851d406eaf0c4d6a7a18c033bcc and 49f3b55de9c7fdfec8cdae49976ce61978890f17 to fix the other compiler errors under gcc-10 for the stable-0.6.0 branch)

stefanberger commented 4 years ago

@salahcoronya Thanks. Backporting those patches to stable-0.6.0: https://github.com/stefanberger/libtpms/pull/134

stefanberger commented 4 years ago

@michaelweiser Merged the fix.

michaelweiser commented 4 years ago

Works a treat. Thank you!