Skip to content

Commit 10b3cc8

Browse files
Add fork test for RAND_poll()
1 parent 0bac2c2 commit 10b3cc8

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/api.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
#endif
5252

5353
#include <stdlib.h>
54+
55+
#ifdef __linux__
56+
#include <unistd.h>
57+
#endif
58+
5459
#include <wolfssl/ssl.h> /* compatibility layer */
5560
#include <wolfssl/error-ssl.h>
5661

@@ -33142,6 +33147,56 @@ static int test_wolfSSL_RAND(void)
3314233147
}
3314333148

3314433149

33150+
static int test_wolfSSL_RAND_poll(void)
33151+
{
33152+
EXPECT_DECLS;
33153+
33154+
#if defined(OPENSSL_EXTRA) && defined(__linux__)
33155+
byte seed[16] = {0};
33156+
byte randbuf[8] = {0};
33157+
int pipefds[2] = {0};
33158+
pid_t pid = 0;
33159+
33160+
XMEMSET(seed, 0, sizeof(seed));
33161+
33162+
/* No global methods set. */
33163+
ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
33164+
33165+
ExpectIntEQ(pipe(pipefds), 0);
33166+
pid = fork();
33167+
if (pid == 0)
33168+
{
33169+
ssize_t n_written = 0;
33170+
33171+
/* Child process. */
33172+
close(pipefds[0]);
33173+
RAND_poll();
33174+
RAND_bytes(randbuf, sizeof(randbuf));
33175+
n_written = write(pipefds[1], randbuf, sizeof(randbuf));
33176+
close(pipefds[1]);
33177+
exit(n_written == sizeof(randbuf) ? 0 : 1);
33178+
}
33179+
else
33180+
{
33181+
/* Parent process. */
33182+
word64 childrand64 = 0;
33183+
33184+
close(pipefds[1]);
33185+
ExpectIntEQ(RAND_poll(), 1);
33186+
ExpectIntEQ(RAND_bytes(randbuf, sizeof(randbuf)), 1);
33187+
ExpectIntEQ(read(pipefds[0], &childrand64, sizeof(childrand64)), sizeof(childrand64));
33188+
ExpectBufNE(randbuf, &childrand64, sizeof(randbuf));
33189+
close(pipefds[0]);
33190+
}
33191+
RAND_cleanup();
33192+
33193+
ExpectIntEQ(RAND_egd(NULL), -1);
33194+
#endif
33195+
33196+
return EXPECT_RESULT();
33197+
}
33198+
33199+
3314533200
static int test_wolfSSL_PKCS8_Compat(void)
3314633201
{
3314733202
EXPECT_DECLS;
@@ -67671,6 +67726,7 @@ TEST_CASE testCases[] = {
6767167726
TEST_DECL(test_wolfSSL_RAND_set_rand_method),
6767267727
TEST_DECL(test_wolfSSL_RAND_bytes),
6767367728
TEST_DECL(test_wolfSSL_RAND),
67729+
TEST_DECL(test_wolfSSL_RAND_poll),
6767467730

6767567731
/* BN compatibility API */
6767667732
TEST_DECL(test_wolfSSL_BN_CTX),

0 commit comments

Comments
 (0)