- Check for failed malloc() in ssl_set_hostname() and x509_get_entries() (Closes ticket #47, found by Hugo Leisink)
diff --git a/ChangeLog b/ChangeLog
index 49e4849..51e9f9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
PolarSSL ChangeLog
+= Version Trunk
+Bugfix
+ * Check for failed malloc() in ssl_set_hostname() and x509_get_entries()
+ (Closes ticket #47, found by Hugo Leisink)
+
= Version 1.1.0 released on 2011-12-22
Features
* Added ssl_session_reset() to allow better multi-connection pools of
diff --git a/include/polarssl/ssl.h b/include/polarssl/ssl.h
index c897a1e..74c5d2d 100644
--- a/include/polarssl/ssl.h
+++ b/include/polarssl/ssl.h
@@ -562,7 +562,7 @@
* \param ssl SSL context
* \param hostname the server hostname
*
- * \return 0 if successful
+ * \return 0 if successful or POLARSSL_ERR_SSL_MALLOC_FAILED
*/
int ssl_set_hostname( ssl_context *ssl, const char *hostname );
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 545317a..44e972c 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -1913,6 +1913,9 @@
ssl->hostname_len = strlen( hostname );
ssl->hostname = (unsigned char *) malloc( ssl->hostname_len + 1 );
+ if( ssl->hostname == NULL )
+ return( POLARSSL_ERR_SSL_MALLOC_FAILED );
+
memcpy( ssl->hostname, (unsigned char *) hostname,
ssl->hostname_len );
diff --git a/library/x509parse.c b/library/x509parse.c
index f561754..ec4fffc 100644
--- a/library/x509parse.c
+++ b/library/x509parse.c
@@ -968,6 +968,10 @@
if ( *p < end )
{
cur_entry->next = malloc( sizeof( x509_crl_entry ) );
+
+ if( cur_entry->next == NULL )
+ return( POLARSSL_ERR_X509_MALLOC_FAILED );
+
cur_entry = cur_entry->next;
memset( cur_entry, 0, sizeof( x509_crl_entry ) );
}