Skip to content

Commit 56a51b5

Browse files
nmouhat8m
authored andcommitted
Update hkdf.c to avoid potentially vulnerable code pattern
The expression "if (a+b>c) a=c-b" is incorrect if "a+b" overflows. It should be replaced by "if (a>c-b) a=c-b", which avoids the potential overflow and is much easier to understand. This pattern is the root cause of CVE-2022-37454, a buffer overflow vulnerability in the "official" SHA-3 implementation. It has been confirmed that the addition in https://github.com/openssl/openssl/blob/master/providers/implementations/kdfs/hkdf.c#L534 cannot overflow. So this is only a minor change proposal to avoid a potentially vulnerable code pattern and to improve readability. More information: github/codeql#12036 (comment) CLA: trivial Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from #20990)
1 parent d500f04 commit 56a51b5

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • providers/implementations/kdfs

‎providers/implementations/kdfs/hkdf.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ static int HKDF_Expand(const EVP_MD *evp_md,
531531
if (!HMAC_Final(hmac, prev, NULL))
532532
goto err;
533533

534-
copy_len = (done_len + dig_len > okm_len) ?
534+
copy_len = (dig_len > okm_len - done_len) ?
535535
okm_len - done_len :
536536
dig_len;
537537

0 commit comments

Comments
 (0)