From da386691a1ad3219da47dff3d27bb1dfd38dfe45 Mon Sep 17 00:00:00 2001 From: toddouska Date: Tue, 20 Nov 2012 12:45:24 -0800 Subject: [PATCH] allow no end of line on last line of PEMs --- ctaocrypt/test/test.c | 1 - src/ssl.c | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ctaocrypt/test/test.c b/ctaocrypt/test/test.c index 0d845a126..989a52a82 100644 --- a/ctaocrypt/test/test.c +++ b/ctaocrypt/test/test.c @@ -123,7 +123,6 @@ int pbkdf2_test(void); int ecc_test(void); #endif -int PemToDer(const char* inName, const char* outName); static void err_sys(const char* msg, int es) diff --git a/src/ssl.c b/src/ssl.c index 1a52e42ad..8a500076a 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -895,6 +895,7 @@ int AddCA(CYASSL_CERT_MANAGER* cm, buffer der, int type, int verify) char* headerEnd; char* footerEnd; char* consumedEnd; + char* bufferEnd = (char*)(buff + longSz); long neededSz; int pkcs8 = 0; int pkcs8Enc = 0; @@ -965,7 +966,7 @@ int AddCA(CYASSL_CERT_MANAGER* cm, buffer der, int type, int verify) } headerEnd += XSTRLEN(header); - /* get next line */ + /* eat end of line */ if (headerEnd[0] == '\n') headerEnd++; else if (headerEnd[1] == '\n') @@ -1023,13 +1024,15 @@ int AddCA(CYASSL_CERT_MANAGER* cm, buffer der, int type, int verify) consumedEnd = footerEnd + XSTRLEN(footer); - /* get next line */ - if (consumedEnd[0] == '\n') - consumedEnd++; - else if (consumedEnd[1] == '\n') - consumedEnd += 2; - else - return SSL_BAD_FILE; + if (consumedEnd < bufferEnd) { /* handle no end of line on last line */ + /* eat end of line */ + if (consumedEnd[0] == '\n') + consumedEnd++; + else if (consumedEnd[1] == '\n') + consumedEnd += 2; + else + return SSL_BAD_FILE; + } if (info) info->consumed = (long)(consumedEnd - (char*)buff);