From d766233a1230ff4a3bd28ef2879f1d65ae9fc3b5 Mon Sep 17 00:00:00 2001 From: Alexey Sheplyakov Date: Thu, 1 Jun 2023 04:50:32 +0000 Subject: [PATCH] Fixed build error with GCC 13 GCC 13 complains: [1382/1456] CC obj/cmd/ecperf/ecperf.ecperf.o FAILED: obj/cmd/ecperf/ecperf.ecperf.o gcc -MMD -MF obj/cmd/ecperf/ecperf.ecperf.o.d -DNSS_USE_STATIC_LIBS -DNSS_FIPS_DISABLED -DNSS_NO_INIT_SUPPORT -DNSS_USE _64 -DUSE_UTIL_DIRECTLY -DNO_NSPR_10_SUPPORT -DSSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -DLINUX2_1 -DLINUX -Dlinux -D_ DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -DSDB_MEASURE_USE_TEMP_DIR -DHAVE_STRERROR -DXP_UNIX -D_REENTRANT -DNDEBUG -I../../lib/softoken -I/usr/include/nspr -I/usr/src/RPM/BUILD/nss-3.89.0/dist/private/nss -I/usr/src/RPM/BUILD/nss-3.8 9.0/dist/public/dbm -I/usr/src/RPM/BUILD/nss-3.89.0/dist/public/nss -fPIC -pipe -ffunction-sections -fdata-sections -We rror -Wall -Wshadow -O2 -std=c99 -c ../../cmd/ecperf/ecperf.c -o obj/cmd/ecperf/ecperf.ecperf.o ../../cmd/ecperf/ecperf.c: In function 'genericThread': ../../cmd/ecperf/ecperf.c:99:24: error: storing the address of local variable 'sig' in '*threadData.p2' [-Werror=dangli ng-pointer=] 99 | threadData->p2 = (void *)&sig; | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~ ../../cmd/ecperf/ecperf.c:91:13: note: 'sig' declared here 91 | SECItem sig; | ^~~ ../../cmd/ecperf/ecperf.c:86:21: note: 'data' declared here 86 | genericThread(void *data) | ~~~~~~^~~~ ../../cmd/ecperf/ecperf.c: In function 'PKCS11Thread': ../../cmd/ecperf/ecperf.c:71:24: error: storing the address of local variable 'sig' in '*threadData.p2' [-Werror=dangli ng-pointer=] 71 | threadData->p2 = (void *)&sig; | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~ ../../cmd/ecperf/ecperf.c:53:13: note: 'sig' declared here 53 | SECItem sig; | ^~~ ../../cmd/ecperf/ecperf.c:47:20: note: 'data' declared here 47 | PKCS11Thread(void *data) | ~~~~~~^~~~ cc1: all warnings being treated as errors Indeed genericThread (and PKCS11Thread) do store the address of the local variable, and that address is reachable after genericThread function returns. However the main thread never reads threadData->p2, but GCC is unable to guess it, and gives the above warning (which is an error with -Werror). Use a local variable for passing the parameter to (*op) to avoid the problem. --- cmd/ecperf/ecperf.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/ecperf/ecperf.c b/cmd/ecperf/ecperf.c index 705d68f3..ee7225b6 100644 --- a/cmd/ecperf/ecperf.c +++ b/cmd/ecperf/ecperf.c @@ -53,6 +53,8 @@ PKCS11Thread(void *data) SECItem sig; CK_SESSION_HANDLE session; CK_RV crv; + /* XXX: avoid storing the address of the local variable into threadData */ + void *p2 = threadData->p2; threadData->status = SECSuccess; threadData->count = 0; @@ -68,12 +70,12 @@ PKCS11Thread(void *data) if (threadData->isSign) { sig.data = sigData; sig.len = sizeof(sigData); - threadData->p2 = (void *)&sig; + p2 = (void *)&sig; } while (iters--) { threadData->status = (*op)(session, threadData->p1, - threadData->p2, threadData->p3); + p2, threadData->p3); if (threadData->status != SECSuccess) { break; } @@ -89,19 +91,22 @@ genericThread(void *data) int iters = threadData->iters; unsigned char sigData[256]; SECItem sig; + /* XXX: avoid storing the address of the local variable into threadData */ + void *p2 = threadData->p2; threadData->status = SECSuccess; threadData->count = 0; if (threadData->isSign) { + sig.data = sigData; sig.len = sizeof(sigData); - threadData->p2 = (void *)&sig; + p2 = (void *)&sig; } while (iters--) { threadData->status = (*threadData->op)(threadData->p1, - threadData->p2, threadData->p3); + p2, threadData->p3); if (threadData->status != SECSuccess) { break; } -- 2.33.3