Skip to content

Commit 47cf634

Browse files
add a way to restore previous pid behavior
1 parent 4207aff commit 47cf634

5 files changed

Lines changed: 15 additions & 8 deletions

File tree

.github/workflows/os-check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ jobs:
4949
'--enable-dtls --enable-dtls13 --enable-dtls-frag-ch
5050
--enable-dtls-mtu CPPFLAGS=-DWOLFSSL_DTLS_RECORDS_CAN_SPAN_DATAGRAMS',
5151
'--enable-opensslall --enable-opensslextra CPPFLAGS=-DWC_RNG_SEED_CB',
52+
'--enable-opensslall --enable-opensslextra
53+
CPPFLAGS='-DWC_RNG_SEED_CB -DWOLFSSL_NO_GETPID'',
5254
]
5355
name: make check
5456
if: github.repository_owner == 'wolfssl'

src/ssl.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25500,7 +25500,8 @@ static int wolfSSL_RAND_InitMutex(void)
2550025500

2550125501
#ifdef OPENSSL_EXTRA
2550225502

25503-
#if defined(HAVE_GETPID) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
25503+
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \
25504+
defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
2550425505
/* In older FIPS bundles add check for reseed here since it does not exist in
2550525506
* the older random.c certified files. */
2550625507
static pid_t currentRandPid = 0;
@@ -25518,8 +25519,8 @@ int wolfSSL_RAND_Init(void)
2551825519
if (initGlobalRNG == 0) {
2551925520
ret = wc_InitRng(&globalRNG);
2552025521
if (ret == 0) {
25521-
#if defined(HAVE_GETPID) && defined(HAVE_FIPS) && \
25522-
FIPS_VERSION3_LT(6,0,0)
25522+
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \
25523+
defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
2552325524
currentRandPid = getpid();
2552425525
#endif
2552525526
initGlobalRNG = 1;
@@ -25999,8 +26000,8 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num)
2599926000
* have the lock.
2600026001
*/
2600126002
if (initGlobalRNG) {
26002-
#if defined(HAVE_GETPID) && defined(HAVE_FIPS) && \
26003-
FIPS_VERSION3_LT(6,0,0)
26003+
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID) && \
26004+
defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
2600426005
pid_t p;
2600526006

2600626007
p = getpid();

tests/api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33159,7 +33159,11 @@ static int test_wolfSSL_RAND_bytes(void)
3315933159
ExpectIntEQ(RAND_bytes(randbuf, sizeof(randbuf)), 1);
3316033160
ExpectIntEQ(read(pipefds[0], &childrand64, sizeof(childrand64)),
3316133161
sizeof(childrand64));
33162+
#ifdef WOLFSSL_NO_GETPID
33163+
ExpectBufEQ(randbuf, &childrand64, sizeof(randbuf));
33164+
#else
3316233165
ExpectBufNE(randbuf, &childrand64, sizeof(randbuf));
33166+
#endif
3316333167
close(pipefds[0]);
3316433168
waitpid(pid, &waitstatus, 0);
3316533169
}

wolfcrypt/src/random.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
16401640
#else
16411641
rng->heap = heap;
16421642
#endif
1643-
#ifdef HAVE_GETPID
1643+
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID)
16441644
rng->pid = getpid();
16451645
#endif
16461646
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
@@ -2014,7 +2014,7 @@ int wc_RNG_GenerateBlock(WC_RNG* rng, byte* output, word32 sz)
20142014
if (rng->status != DRBG_OK)
20152015
return RNG_FAILURE_E;
20162016

2017-
#ifdef HAVE_GETPID
2017+
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID)
20182018
if (rng->pid != getpid()) {
20192019
rng->pid = getpid();
20202020
ret = PollAndReSeed(rng);

wolfssl/wolfcrypt/random.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ struct WC_RNG {
189189
#endif
190190
byte status;
191191
#endif
192-
#ifdef HAVE_GETPID
192+
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID)
193193
pid_t pid;
194194
#endif
195195
#ifdef WOLFSSL_ASYNC_CRYPT

0 commit comments

Comments
 (0)