/* Provenance: openssl/openssl bmp_to_utf8 (fixed). * repo: openssl/openssl * commit: 4191043c36f1a50c717a2d0075fc6f3b9bc0afc5 * parent: 7565bb46fa2979511cb27aad1c2bd6b80adf7352 * commit_url: https://github.com/openssl/openssl/commit/4191043c36f1a50c717a2d0075fc6f3b9bc0afc5 * cve: CVE-2025-69419 * license: Apache-2.0 * function: bmp_to_utf8 * relpath: crypto/pkcs12/p12_utl.c */ static int bmp_to_utf8(char *str, const unsigned char *utf16, int len) { unsigned long utf32chr; if (len == 0) return 0; if (len < 2) return -1; /* pull UTF-16 character in big-endian order */ utf32chr = (utf16[0] << 8) | utf16[1]; if (utf32chr >= 0xD800 && utf32chr < 0xE000) { /* two chars */ unsigned int lo; if (len < 4) return -1; utf32chr -= 0xD800; utf32chr <<= 10; lo = (utf16[2] << 8) | utf16[3]; if (lo < 0xDC00 || lo >= 0xE000) return -1; utf32chr |= lo - 0xDC00; utf32chr += 0x10000; } return UTF8_putc((unsigned char *)str, 4, utf32chr); }