Skip to content

Commit 41be0f2

Browse files
committed
Check return code of UTF8_putc
Signed-off-by: Norbert Pocs <norbertp@openssl.org> Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org> Reviewed-by: Viktor Dukhovni <viktor@openssl.org> (Merged from #29376)
1 parent fc70e91 commit 41be0f2

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

crypto/asn1/a_strex.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,10 @@ static int do_buf(unsigned char *buf, int buflen,
198198
orflags = CHARTYPE_LAST_ESC_2253;
199199
if (type & BUF_TYPE_CONVUTF8) {
200200
unsigned char utfbuf[6];
201-
int utflen;
202-
utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c);
201+
int utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c);
202+
203+
if (utflen < 0)
204+
return -1; /* error happened with UTF8 */
203205
for (i = 0; i < utflen; i++) {
204206
/*
205207
* We don't need to worry about setting orflags correctly

crypto/pkcs12/p12_utl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen)
219219
/* re-run the loop emitting UTF-8 string */
220220
for (asclen = 0, i = 0; i < unilen;) {
221221
j = bmp_to_utf8(asctmp + asclen, uni + i, unilen - i);
222+
/* when UTF8_putc fails */
223+
if (j < 0) {
224+
OPENSSL_free(asctmp);
225+
return NULL;
226+
}
222227
if (j == 4)
223228
i += 4;
224229
else

0 commit comments

Comments
 (0)