From 59ccb72cd5cec3b4e312853621e12a68dacdbc7e Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Fri, 14 Jan 2022 16:22:41 +0530 Subject: Fix invalid malloc failures in PEM_write_bio_PKCS8PrivateKey() When `PEM_write_bio_PKCS8PrivateKey()` was passed an empty passphrase string, `OPENSSL_memdup()` was incorrectly getting used for 0 bytes size allocation, which resulted in malloc failures. Fixes: https://github.com/openssl/openssl/issues/17506 Signed-off-by: Darshan Sen Reviewed-by: Bernd Edlinger Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/17507) --- crypto/ui/ui_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crypto/ui') diff --git a/crypto/ui/ui_util.c b/crypto/ui/ui_util.c index 58769d68a3..871472cd32 100644 --- a/crypto/ui/ui_util.c +++ b/crypto/ui/ui_util.c @@ -114,7 +114,7 @@ static int ui_read(UI *ui, UI_STRING *uis) if (len >= 0) result[len] = '\0'; - if (len <= 0) + if (len < 0) return len; if (UI_set_result_ex(ui, uis, result, len) >= 0) return 1; -- cgit v1.2.1