From 0e7aa6bf9e0a7a91136353a3d6fe6a90d2047fc0 Mon Sep 17 00:00:00 2001 From: Yi Li Date: Mon, 26 Sep 2022 08:24:33 +0800 Subject: [PATCH] CryptoPkg: Fix pem heap-buffer-overflow due to BIO_snprintf() REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4075 Fake BIO_snprintf() does not actually print anything to buf, it should return -1 as error. 0 will be considered a correct return value, the consumer may think that the buf is valid and parse the buffer. please refer to bugzilla link for details. Cc: Jiewen Yao Cc: Jian J Wang Cc: Xiaoyu Lu Cc: Guomin Jiang Signed-off-by: Yi Li Reviewed-by: Jiewen Yao --- CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c b/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c index c1fc33538f..b65d29485b 100644 --- a/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c +++ b/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c @@ -494,7 +494,9 @@ BIO_snprintf ( ... ) { - return 0; + // Because the function does not actually print anything to buf, it returns -1 as error. + // Otherwise, the consumer may think that the buf is valid and parse the buffer. + return -1; } #ifdef __GNUC__