Fix heap-buffer-overflow issues in wolfSSL_SMIME_read_PKCS7

This commit is contained in:
Eric Blankenhorn
2021-05-10 11:46:52 -05:00
parent 1cd8bd3a94
commit a68542e6f4

View File

@@ -54583,17 +54583,23 @@ WOLFSSL_API PKCS7* wolfSSL_SMIME_read_PKCS7(WOLFSSL_BIO* in,
} }
} }
if (canonPos > 0) {
canonPos--; canonPos--;
}
/* Strip the final trailing newline. Support \r, \n or \r\n. */ /* Strip the final trailing newline. Support \r, \n or \r\n. */
if (canonSection[canonPos] == '\n') { if (canonSection[canonPos] == '\n') {
if (canonPos > 0) {
canonPos--; canonPos--;
}
}
if (canonSection[canonPos] == '\r') { if (canonSection[canonPos] == '\r') {
if (canonPos > 0) {
canonPos--; canonPos--;
} }
} }
else if (canonSection[canonPos] == '\r') {
canonPos--;
}
canonSection[canonPos+1] = '\0'; canonSection[canonPos+1] = '\0';
*bcont = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()); *bcont = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
@@ -54706,8 +54712,8 @@ WOLFSSL_API PKCS7* wolfSSL_SMIME_read_PKCS7(WOLFSSL_BIO* in,
goto error; goto error;
} }
/* Strip trailing newlines. */ /* Strip trailing newlines. */
while ((section[sectionLen-1] == '\r' || section[sectionLen-1] == '\n') && while ((sectionLen > 0) &&
sectionLen > 0) { (section[sectionLen-1] == '\r' || section[sectionLen-1] == '\n')) {
sectionLen--; sectionLen--;
} }
section[sectionLen] = '\0'; section[sectionLen] = '\0';