Skip to content

Commit cda12de

Browse files
committed
Check return code of UTF8_putc
Signed-off-by: Norbert Pocs <[email protected]> Reviewed-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Viktor Dukhovni <[email protected]> (Merged from #29376)
1 parent 6ea99ad commit cda12de

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
@@ -213,6 +213,11 @@ char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen)
213213
/* re-run the loop emitting UTF-8 string */
214214
for (asclen = 0, i = 0; i < unilen;) {
215215
j = bmp_to_utf8(asctmp + asclen, uni + i, unilen - i);
216+
/* when UTF8_putc fails */
217+
if (j < 0) {
218+
OPENSSL_free(asctmp);
219+
return NULL;
220+
}
216221
if (j == 4)
217222
i += 4;
218223
else

0 commit comments

Comments
 (0)