|
| 1 | +From 7c55e722e1ee27020d9e52df9a194c2e3a5ab4de Mon Sep 17 00:00:00 2001 |
| 2 | +From: AllSpark <allspark@microsoft.com> |
| 3 | +Date: Mon, 9 Feb 2026 11:04:29 +0000 |
| 4 | +Subject: [PATCH] Check return code of UTF8_putc: handle failure in ASN.1 |
| 5 | + string conversion and PKCS12 UTF-8 emission per upstream patch. Preserves |
| 6 | + comments from patch. |
| 7 | + |
| 8 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 9 | +Upstream-reference: AI Backport of https://github.com/openssl/openssl/commit/41be0f216404f14457bbf3b9cc488dba60b49296.patch |
| 10 | +--- |
| 11 | + .../Library/OpensslLib/openssl/crypto/asn1/a_strex.c | 6 ++++-- |
| 12 | + .../OpensslLib/openssl/crypto/pkcs12/p12_utl.c | 11 +++++++++-- |
| 13 | + 2 files changed, 13 insertions(+), 4 deletions(-) |
| 14 | + |
| 15 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/a_strex.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/a_strex.c |
| 16 | +index 284dde27..843b0f94 100644 |
| 17 | +--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/a_strex.c |
| 18 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/a_strex.c |
| 19 | +@@ -203,8 +203,10 @@ static int do_buf(unsigned char *buf, int buflen, |
| 20 | + orflags = CHARTYPE_LAST_ESC_2253; |
| 21 | + if (type & BUF_TYPE_CONVUTF8) { |
| 22 | + unsigned char utfbuf[6]; |
| 23 | +- int utflen; |
| 24 | +- utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c); |
| 25 | ++ int utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c); |
| 26 | ++ |
| 27 | ++ if (utflen < 0) |
| 28 | ++ return -1; /* error happened with UTF8 */ |
| 29 | + for (i = 0; i < utflen; i++) { |
| 30 | + /* |
| 31 | + * We don't need to worry about setting orflags correctly |
| 32 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs12/p12_utl.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs12/p12_utl.c |
| 33 | +index 43b9e3a5..1c6b59d5 100644 |
| 34 | +--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs12/p12_utl.c |
| 35 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs12/p12_utl.c |
| 36 | +@@ -207,8 +207,15 @@ char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen) |
| 37 | + /* re-run the loop emitting UTF-8 string */ |
| 38 | + for (asclen = 0, i = 0; i < unilen; ) { |
| 39 | + j = bmp_to_utf8(asctmp+asclen, uni+i, unilen-i); |
| 40 | +- if (j == 4) i += 4; |
| 41 | +- else i += 2; |
| 42 | ++ /* when UTF8_putc fails */ |
| 43 | ++ if (j < 0) { |
| 44 | ++ OPENSSL_free(asctmp); |
| 45 | ++ return NULL; |
| 46 | ++ } |
| 47 | ++ if (j == 4) |
| 48 | ++ i += 4; |
| 49 | ++ else |
| 50 | ++ i += 2; |
| 51 | + asclen += j; |
| 52 | + } |
| 53 | + |
| 54 | +-- |
| 55 | +2.45.4 |
| 56 | + |
0 commit comments