]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test: fix unreachable code in test_kdf_pbkdf2_large_output in evp_kdf_test.c
authorAnton Moryakov <ant.v.moryakov@gmail.com>
Sun, 31 May 2026 09:33:11 +0000 (12:33 +0300)
committerNikola Pajkovsky <nikolap@openssl.org>
Tue, 2 Jun 2026 11:09:59 +0000 (13:09 +0200)
The condition `if (sizeof(len) > 32)` was intended to set `len` to
SIZE_MAX on platforms where size_t can hold values larger than 32 bits.
However, sizeof() returns the size in bytes, not bits. Since sizeof(size_t)
is typically 4 or 8 bytes on all current platforms, the condition was
always false, leaving len at 0 and skipping the large-output test.

This commit fixes the check by comparing SIZE_MAX directly against
0xFFFFFFFFU, which correctly detects whether size_t can represent
values exceeding 32-bit range. This ensures the test properly validates
PBKDF2 behavior when requested output length is excessively large.

Fixes: 1cae59d14b9e "Make KDFs fail if requesting a zero-length key."
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Daniel Kubec <kubec@openssl.foundation>
MergeDate: Tue Jun  2 11:10:23 2026
(Merged from https://github.com/openssl/openssl/pull/31344)

test/evp_kdf_test.c

index 5f0b3f525de83c239570f7c70758f328421e0336..a6ae0b16c47cf26b085e7cc1fd119471dc4d874b 100644 (file)
@@ -988,7 +988,7 @@ static int test_kdf_pbkdf2_large_output(void)
     int mode = 0;
     OSSL_PARAM *params;
 
-    if (sizeof(len) > 32)
+    if (SIZE_MAX > 0xFFFFFFFFU)
         len = SIZE_MAX;
 
     params = construct_pbkdf2_params("passwordPASSWORDpassword", "sha256",