From 358f94a71c81bdaf95c5cab0e5ce79c541bf2cf9 Mon Sep 17 00:00:00 2001 From: Ashley Duncan Date: Fri, 11 Feb 2022 09:57:18 +1300 Subject: [PATCH] Fixed undefined behavior in ssl_read if buf parameter is NULL. Signed-off-by: Ashley Duncan --- library/ssl_msg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/ssl_msg.c b/library/ssl_msg.c index d26d95086..1162cca02 100644 --- a/library/ssl_msg.c +++ b/library/ssl_msg.c @@ -5593,8 +5593,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 (buf) { + memcpy(buf, ssl->in_offt, n); + ssl->in_msglen -= n; + } /* Zeroising the plaintext buffer to erase unused application data from the memory. */