From: Pauli Date: Wed, 4 Jun 2025 23:50:20 +0000 (+1000) Subject: rand: add unit test exhibiting memory overrun X-Git-Tag: openssl-3.3.4~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=978efd6c26b4e4512dcd3a7e4c12313f750f57a5;p=thirdparty%2Fopenssl.git rand: add unit test exhibiting memory overrun Reviewed-by: Tom Cosgrove Reviewed-by: Saša Nedvědický Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/27766) (cherry picked from commit 6d490a92fe49ea6e41cb7874086dbad5462078c6) --- diff --git a/test/rand_test.c b/test/rand_test.c index 9f96b9b6dbb..0cf940f933b 100644 --- a/test/rand_test.c +++ b/test/rand_test.c @@ -20,6 +20,7 @@ static int test_rand(void) OSSL_PARAM params[2], *p = params; unsigned char entropy1[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; unsigned char entropy2[] = { 0xff, 0xfe, 0xfd }; + unsigned char nonce[] = { 0x00, 0x01, 0x02, 0x03, 0x04 }; unsigned char outbuf[3]; *p++ = OSSL_PARAM_construct_octet_string(OSSL_RAND_PARAM_TEST_ENTROPY, @@ -42,6 +43,13 @@ static int test_rand(void) || !TEST_int_gt(RAND_priv_bytes(outbuf, sizeof(outbuf)), 0) || !TEST_mem_eq(outbuf, sizeof(outbuf), entropy2, sizeof(outbuf))) return 0; + + *params = OSSL_PARAM_construct_octet_string(OSSL_RAND_PARAM_TEST_NONCE, + nonce, sizeof(nonce)); + if (!TEST_true(EVP_RAND_CTX_set_params(privctx, params)) + || !TEST_true(EVP_RAND_nonce(privctx, outbuf, sizeof(outbuf))) + || !TEST_mem_eq(outbuf, sizeof(outbuf), nonce, sizeof(outbuf))) + return 0; return 1; }