Skip to content

Commit 978a29d

Browse files
authored
Merge pull request #8898 from cconlon/getpidOptionsH
Add HAVE_GETPID to options.h if getpid detected
2 parents c4428a4 + 9ee212c commit 978a29d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ fi
160160
#ifdef HAVE_STDLIB_H
161161
#include <stdlib.h>
162162
#endif
163+
#ifdef HAVE_UNISTD_H
164+
#include <unistd.h>
165+
#endif
163166
#ifdef HAVE_CTYPE_H
164167
#include <ctype.h>
165168
#endif
@@ -10524,6 +10527,12 @@ then
1052410527
AM_CFLAGS="$AM_CFLAGS -DHAVE___UINT128_T=1"
1052510528
fi
1052610529
10530+
# Add HAVE_GETPID to AM_CFLAGS for inclusion in options.h
10531+
if test "$ac_cv_func_getpid" = "yes"
10532+
then
10533+
AM_CFLAGS="$AM_CFLAGS -DHAVE_GETPID=1"
10534+
fi
10535+
1052710536
LIB_SOCKET_NSL
1052810537
AX_HARDEN_CC_COMPILER_FLAGS
1052910538

src/ssl.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25515,7 +25515,7 @@ static int wolfSSL_RAND_InitMutex(void)
2551525515
#ifdef OPENSSL_EXTRA
2551625516

2551725517
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \
25518-
defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
25518+
((defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)) || defined(HAVE_SELFTEST))
2551925519
/* In older FIPS bundles add check for reseed here since it does not exist in
2552025520
* the older random.c certified files. */
2552125521
static pid_t currentRandPid = 0;
@@ -25534,7 +25534,9 @@ int wolfSSL_RAND_Init(void)
2553425534
ret = wc_InitRng(&globalRNG);
2553525535
if (ret == 0) {
2553625536
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \
25537-
defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
25537+
((defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)) || \
25538+
defined(HAVE_SELFTEST))
25539+
2553825540
currentRandPid = getpid();
2553925541
#endif
2554025542
initGlobalRNG = 1;
@@ -26015,7 +26017,8 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num)
2601526017
*/
2601626018
if (initGlobalRNG) {
2601726019
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \
26018-
defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
26020+
((defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)) || \
26021+
defined(HAVE_SELFTEST))
2601926022
pid_t p;
2602026023

2602126024
p = getpid();

tests/api.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33212,7 +33212,7 @@ static int test_wolfSSL_RAND_bytes(void)
3321233212

3321333213
max_bufsize = size4;
3321433214

33215-
ExpectNotNull(my_buf = (byte*)XMALLOC(max_bufsize * sizeof(byte), NULL,
33215+
ExpectNotNull(my_buf = (byte*)XMALLOC(max_bufsize * sizeof(byte), HEAP_HINT,
3321633216
DYNAMIC_TYPE_TMP_BUFFER));
3321733217

3321833218
ExpectIntEQ(RAND_bytes(my_buf, 0), 1);
@@ -33223,6 +33223,7 @@ static int test_wolfSSL_RAND_bytes(void)
3322333223
ExpectIntEQ(RAND_bytes(my_buf, size2), 1);
3322433224
ExpectIntEQ(RAND_bytes(my_buf, size3), 1);
3322533225
ExpectIntEQ(RAND_bytes(my_buf, size4), 1);
33226+
XFREE(my_buf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
3322633227

3322733228
#if defined(OPENSSL_EXTRA) && defined(HAVE_GETPID)
3322833229
XMEMSET(seed, 0, sizeof(seed));
@@ -33263,8 +33264,6 @@ static int test_wolfSSL_RAND_bytes(void)
3326333264
}
3326433265
RAND_cleanup();
3326533266
#endif
33266-
33267-
XFREE(my_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
3326833267
#endif
3326933268
return EXPECT_RESULT();
3327033269
}

0 commit comments

Comments
 (0)