Fixed potential heap buffer overflow on large hostname setting
(cherry picked from commit 75c1a6f97c9b25b71bcc95b158bc673f6db04400)
Conflicts:
library/ssl_tls.c
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 73a6604..b3b82b0 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -1991,6 +1991,10 @@
return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
ssl->hostname_len = strlen( hostname );
+
+ if( ssl->hostname_len + 1 == 0 )
+ return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
+
ssl->hostname = (unsigned char *) malloc( ssl->hostname_len + 1 );
if( ssl->hostname == NULL )
@@ -1998,7 +2002,7 @@
memcpy( ssl->hostname, (unsigned char *) hostname,
ssl->hostname_len );
-
+
ssl->hostname[ssl->hostname_len] = '\0';
return( 0 );