Commit 24d208262a for openssl.org
commit 24d208262acba826724860c568160cb04367068f
Author: Jakub Zelenka <jakub.zelenka@openssl.foundation>
Date: Tue Jul 7 16:33:12 2026 +0200
test-rng: handle nonce length query in generate mode
The DRBG instantiation probes the parent nonce callback with a NULL
output buffer to obtain the nonce length before requesting the actual
nonce. The generate mode branch of test_rng_nonce() wrote the bytes
without checking the output pointer, crashing when TEST-RAND with
generate=1 is used as a DRBG parent. The entropy-buffer branch already
handles a NULL output correctly.
Assisted-by: Claude:claude-fable-5
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
MergeDate: Fri Jul 10 15:47:15 2026
(Merged from https://github.com/openssl/openssl/pull/31885)
diff --git a/providers/implementations/rands/test_rng.c b/providers/implementations/rands/test_rng.c
index 78fef9549e..c073b3e5bf 100644
--- a/providers/implementations/rands/test_rng.c
+++ b/providers/implementations/rands/test_rng.c
@@ -170,8 +170,9 @@ static size_t test_rng_nonce(void *vtest, unsigned char *out,
return 0;
if (t->generate) {
- for (i = 0; i < min_noncelen; i++)
- out[i] = gen_byte(t);
+ if (out != NULL)
+ for (i = 0; i < min_noncelen; i++)
+ out[i] = gen_byte(t);
return min_noncelen;
}