diff --git a/configure.ac b/configure.ac index be71d48f8..21dfb0c79 100644 --- a/configure.ac +++ b/configure.ac @@ -160,6 +160,9 @@ fi #ifdef HAVE_STDLIB_H #include #endif +#ifdef HAVE_UNISTD_H + #include +#endif #ifdef HAVE_CTYPE_H #include #endif @@ -10524,6 +10527,12 @@ then AM_CFLAGS="$AM_CFLAGS -DHAVE___UINT128_T=1" fi +# Add HAVE_GETPID to AM_CFLAGS for inclusion in options.h +if test "$ac_cv_func_getpid" = "yes" +then + AM_CFLAGS="$AM_CFLAGS -DHAVE_GETPID=1" +fi + LIB_SOCKET_NSL AX_HARDEN_CC_COMPILER_FLAGS diff --git a/src/ssl.c b/src/ssl.c index bf6fc990c..a188b87f1 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -25515,7 +25515,7 @@ static int wolfSSL_RAND_InitMutex(void) #ifdef OPENSSL_EXTRA #if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \ - defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) + ((defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)) || defined(HAVE_SELFTEST)) /* In older FIPS bundles add check for reseed here since it does not exist in * the older random.c certified files. */ static pid_t currentRandPid = 0; @@ -25534,7 +25534,9 @@ int wolfSSL_RAND_Init(void) ret = wc_InitRng(&globalRNG); if (ret == 0) { #if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \ - defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) + ((defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)) || \ + defined(HAVE_SELFTEST)) + currentRandPid = getpid(); #endif initGlobalRNG = 1; @@ -26015,7 +26017,8 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num) */ if (initGlobalRNG) { #if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \ - defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) + ((defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)) || \ + defined(HAVE_SELFTEST)) pid_t p; p = getpid(); diff --git a/tests/api.c b/tests/api.c index 5e2e94791..14295bbd6 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33212,7 +33212,7 @@ static int test_wolfSSL_RAND_bytes(void) max_bufsize = size4; - ExpectNotNull(my_buf = (byte*)XMALLOC(max_bufsize * sizeof(byte), NULL, + ExpectNotNull(my_buf = (byte*)XMALLOC(max_bufsize * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)); ExpectIntEQ(RAND_bytes(my_buf, 0), 1); @@ -33223,6 +33223,7 @@ static int test_wolfSSL_RAND_bytes(void) ExpectIntEQ(RAND_bytes(my_buf, size2), 1); ExpectIntEQ(RAND_bytes(my_buf, size3), 1); ExpectIntEQ(RAND_bytes(my_buf, size4), 1); + XFREE(my_buf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #if defined(OPENSSL_EXTRA) && defined(HAVE_GETPID) XMEMSET(seed, 0, sizeof(seed)); @@ -33263,8 +33264,6 @@ static int test_wolfSSL_RAND_bytes(void) } RAND_cleanup(); #endif - - XFREE(my_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return EXPECT_RESULT(); }