#endif
/* Some helpers for PEM_read_bio_ex(). */
-static int sanitize_line(char *linebuf, int len, unsigned int flags)
+static int sanitize_line(char *linebuf, int len, unsigned int flags, int first_call)
{
int i;
+ if (first_call) {
+ /* Other BOMs imply unsupported multibyte encoding,
+ * so don't strip them and let the error raise */
+ const unsigned char utf8_bom[3] = {0xEF, 0xBB, 0xBF};
+
+ if (len > 3 && memcmp(linebuf, utf8_bom, 3) == 0) {
+ memmove(linebuf, linebuf + 3, len - 3);
+ linebuf[len - 3] = 0;
+ len -= 3;
+ }
+ }
if (flags & PEM_FLAG_EAY_COMPATIBLE) {
/* Strip trailing whitespace */
char *linebuf;
int ret = 0;
int len;
+ int first_call = 1;
/*
* Need to hold trailing NUL (accounted for by BIO_gets() and the newline
}
/* Strip trailing garbage and standardize ending. */
- len = sanitize_line(linebuf, len, flags & ~PEM_FLAG_ONLY_B64);
+ len = sanitize_line(linebuf, len, flags & ~PEM_FLAG_ONLY_B64, first_call);
+ first_call = 0;
/* Allow leading empty or non-matching lines. */
} while (strncmp(linebuf, beginstr, BEGINLEN) != 0
}
if (!strncmp(linebuf, endstr, ENDLEN) || got_header == IN_HEADER)
flags_mask &= ~PEM_FLAG_ONLY_B64;
- len = sanitize_line(linebuf, len, flags & flags_mask);
+ len = sanitize_line(linebuf, len, flags & flags_mask, 0);
/* Check for end of header. */
if (linebuf[0] == '\n') {
--- /dev/null
+-----BEGIN CERTIFICATE-----
+MIIEzDCCA7QCCQCgxkRox+YljjANBgkqhkiG9w0BAQsFADCCASYxYzBhBgNVBAgM
+WlRoZSBHcmVhdCBTdGF0ZSBvZiBMb25nLVdpbmRlZCBDZXJ0aWZpY2F0ZSBGaWVs
+ZCBOYW1lcyBXaGVyZWJ5IHRvIEluY3JlYXNlIHRoZSBPdXRwdXQgU2l6ZTEfMB0G
+A1UEBwwWVG9vbWFueWNoYXJhY3RlcnN2aWxsZTFIMEYGA1UECgw/VGhlIEJlbmV2
+b2xlbnQgU29jaWV0eSBvZiBMb3F1Y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