mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge pull request #7171 from daverodgman/pr5527
Fix undefined behavior in ssl_read if buf parameter is NULL
This commit is contained in:
@ -5599,8 +5599,10 @@ int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len)
|
||||
n = (len < ssl->in_msglen)
|
||||
? len : ssl->in_msglen;
|
||||
|
||||
memcpy(buf, ssl->in_offt, n);
|
||||
ssl->in_msglen -= n;
|
||||
if (len != 0) {
|
||||
memcpy(buf, ssl->in_offt, n);
|
||||
ssl->in_msglen -= n;
|
||||
}
|
||||
|
||||
/* Zeroising the plaintext buffer to erase unused application data
|
||||
from the memory. */
|
||||
@ -5676,7 +5678,9 @@ static int ssl_write_real(mbedtls_ssl_context *ssl,
|
||||
*/
|
||||
ssl->out_msglen = len;
|
||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_APPLICATION_DATA;
|
||||
memcpy(ssl->out_msg, buf, len);
|
||||
if (len > 0) {
|
||||
memcpy(ssl->out_msg, buf, len);
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_ssl_write_record(ssl, SSL_FORCE_FLUSH)) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ssl_write_record", ret);
|
||||
|
Reference in New Issue
Block a user