forked from wolfSSL/wolfssl
Merge pull request #4013 from kabuobeid/smime_fixes
S/MIME: Fix issue with canonSection size when adding newlines.
This commit is contained in:
14
src/ssl.c
14
src/ssl.c
@ -54457,6 +54457,7 @@ WOLFSSL_API PKCS7* wolfSSL_SMIME_read_PKCS7(WOLFSSL_BIO* in,
|
||||
int lineLen = 0;
|
||||
int remainLen = 0;
|
||||
byte isEnd = 0;
|
||||
size_t canonSize = 0;
|
||||
size_t boundLen = 0;
|
||||
char* boundary = NULL;
|
||||
|
||||
@ -54554,7 +54555,8 @@ WOLFSSL_API PKCS7* wolfSSL_SMIME_read_PKCS7(WOLFSSL_BIO* in,
|
||||
|
||||
section[0] = '\0';
|
||||
sectionLen = 0;
|
||||
canonSection = (char*)XMALLOC(remainLen+1, NULL,
|
||||
canonSize = remainLen + 1;
|
||||
canonSection = (char*)XMALLOC(canonSize, NULL,
|
||||
DYNAMIC_TYPE_PKCS7);
|
||||
if (canonSection == NULL) {
|
||||
goto error;
|
||||
@ -54567,6 +54569,16 @@ WOLFSSL_API PKCS7* wolfSSL_SMIME_read_PKCS7(WOLFSSL_BIO* in,
|
||||
if (canonLine == NULL) {
|
||||
goto error;
|
||||
}
|
||||
/* If line endings were added, the initial length may be
|
||||
* exceeded. */
|
||||
if ((canonPos + XSTRLEN(canonLine) + 1) >= canonSize) {
|
||||
canonSize = canonPos + XSTRLEN(canonLine) + 1;
|
||||
canonSection = XREALLOC(canonSection, canonSize, NULL,
|
||||
DYNAMIC_TYPE_PKCS7);
|
||||
if (canonSection == NULL) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
XMEMCPY(&canonSection[canonPos], canonLine,
|
||||
(int)XSTRLEN(canonLine));
|
||||
canonPos += XSTRLEN(canonLine);
|
||||
|
Reference in New Issue
Block a user