Skip to content

Commit 1e5d50f

Browse files
committed
Merge #889: fix uninitialized read in tests
99a1cfe print warnings for conditional-uninitialized (PiRK) 3d2cf6c initialize variable in tests (PiRK) Pull request description: ACKs for top commit: real-or-random: ACK 99a1cfe code inspection jonasnick: ACK 99a1cfe Tree-SHA512: 72f92f51c44210ab54f166920f540525db0e3d1f19a2fa56e4a6d157a38a582f9dc649d919cf3278482c9fd723021b07759284a8fccbc574b62a22aac0facf51
2 parents c083cc6 + 99a1cfe commit 1e5d50f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

configure.ac

+9
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
8282
CFLAGS="$saved_CFLAGS"
8383
])
8484

85+
saved_CFLAGS="$CFLAGS"
86+
CFLAGS="-Wconditional-uninitialized $CFLAGS"
87+
AC_MSG_CHECKING([if ${CC} supports -Wconditional-uninitialized])
88+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
89+
[ AC_MSG_RESULT([yes]) ],
90+
[ AC_MSG_RESULT([no])
91+
CFLAGS="$saved_CFLAGS"
92+
])
93+
8594
saved_CFLAGS="$CFLAGS"
8695
CFLAGS="-fvisibility=hidden $CFLAGS"
8796
AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden])

src/tests.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -4526,8 +4526,10 @@ void test_ecdsa_sign_verify(void) {
45264526
secp256k1_scalar one;
45274527
secp256k1_scalar msg, key;
45284528
secp256k1_scalar sigr, sigs;
4529-
int recid;
45304529
int getrec;
4530+
/* Initialize recid to suppress a false positive -Wconditional-uninitialized in clang.
4531+
VG_UNDEF ensures that valgrind will still treat the variable as uninitialized. */
4532+
int recid = -1; VG_UNDEF(&recid, sizeof(recid));
45314533
random_scalar_order_test(&msg);
45324534
random_scalar_order_test(&key);
45334535
secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &pubj, &key);

0 commit comments

Comments
 (0)