From: Norbert Pocs Date: Thu, 11 Dec 2025 11:49:00 +0000 (+0100) Subject: Check return code of UTF8_putc X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a26a90d38edec3748566129d824e664b54bee2e2;p=thirdparty%2Fopenssl.git Check return code of UTF8_putc Signed-off-by: Norbert Pocs Reviewed-by: Nikola Pajkovsky Reviewed-by: Viktor Dukhovni (Merged from https://github.com/openssl/openssl/pull/29376) --- diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c index 683b8a06fc5..68c2e31a70a 100644 --- a/crypto/asn1/a_strex.c +++ b/crypto/asn1/a_strex.c @@ -198,8 +198,10 @@ static int do_buf(unsigned char *buf, int buflen, orflags = CHARTYPE_LAST_ESC_2253; if (type & BUF_TYPE_CONVUTF8) { unsigned char utfbuf[6]; - int utflen; - utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c); + int utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c); + + if (utflen < 0) + return -1; /* error happened with UTF8 */ for (i = 0; i < utflen; i++) { /* * We don't need to worry about setting orflags correctly diff --git a/crypto/pkcs12/p12_utl.c b/crypto/pkcs12/p12_utl.c index 1669ef5b079..9360f993071 100644 --- a/crypto/pkcs12/p12_utl.c +++ b/crypto/pkcs12/p12_utl.c @@ -213,6 +213,11 @@ char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen) /* re-run the loop emitting UTF-8 string */ for (asclen = 0, i = 0; i < unilen;) { j = bmp_to_utf8(asctmp + asclen, uni + i, unilen - i); + /* when UTF8_putc fails */ + if (j < 0) { + OPENSSL_free(asctmp); + return NULL; + } if (j == 4) i += 4; else