Fix to handle carriage return case in PEM end of line character handling (for Windows). Cleanup to consolidate duplicate end of line character handling code.

This commit is contained in:
David Garske
2018-08-09 08:42:15 -07:00
parent ff7d2fefdc
commit 6ca56ee98c

View File

@ -7556,6 +7556,15 @@ const char* const END_PUB_KEY = "-----END PUBLIC KEY-----";
#endif
static WC_INLINE char* SkipEndOfLineChars(char* line, const char* endOfLine)
{
/* eat end of line characters */
while (line < endOfLine &&
(line[0] == '\r' || line[0] == '\n')) {
line++;
}
return line;
}
int wc_PemGetHeaderFooter(int type, const char** header, const char** footer)
{
@ -7794,11 +7803,8 @@ static int wc_EncryptedInfoParse(EncryptedInfo* info,
else
return BUFFER_E;
/* eat blank line */
while (newline < bufferEnd &&
(*newline == '\r' || *newline == '\n')) {
newline++;
}
/* eat end of line characters */
newline = SkipEndOfLineChars(newline, bufferEnd);
/* return new headerEnd */
if (pBuffer)
@ -8051,19 +8057,8 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
headerEnd += XSTRLEN(header);
if ((headerEnd + 1) >= bufferEnd)
return BUFFER_E;
/* eat end of line */
if (headerEnd[0] == '\n')
headerEnd++;
else if (headerEnd[1] == '\n')
headerEnd += 2;
else {
if (info)
info->consumed = (long)(headerEnd+2 - (char*)buff);
return BUFFER_E;
}
/* eat end of line characters */
headerEnd = SkipEndOfLineChars(headerEnd, bufferEnd);
if (type == PRIVATEKEY_TYPE) {
if (eccKey) {
@ -8096,10 +8091,8 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
consumedEnd = footerEnd + XSTRLEN(footer);
if (consumedEnd < bufferEnd) { /* handle no end of line on last line */
/* eat new line characters */
while (consumedEnd < bufferEnd && consumedEnd[0] == '\n') {
consumedEnd++;
}
/* eat end of line characters */
consumedEnd = SkipEndOfLineChars(consumedEnd, bufferEnd);
}
if (info)