]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Check return code of UTF8_putc
authorNorbert Pocs <norbertp@openssl.org>
Thu, 11 Dec 2025 11:49:00 +0000 (12:49 +0100)
committerNorbert Pocs <norbertp@openssl.org>
Thu, 18 Dec 2025 10:30:50 +0000 (11:30 +0100)
Signed-off-by: Norbert Pocs <norbertp@openssl.org>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/29376)

crypto/asn1/a_strex.c
crypto/pkcs12/p12_utl.c

index 683b8a06fc540a48f71ebe905059e83efa4eda09..68c2e31a70a2874cab8d20a65d36cf45d4339159 100644 (file)
@@ -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
index 1669ef5b07939278fb1fc81adbd0f9561f79f0be..9360f9930713f5bacb2558cc4f3646298797e2bc 100644 (file)
@@ -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