diff --git a/lib/vtls/nss.c b/lib/vtls/nss.c
index c66c60b5617b4bfd720de2de1ef36380de3b4cc4..048273cf2c41b6960a24a11fae8e092d58b144f6 100644
--- a/lib/vtls/nss.c
+++ b/lib/vtls/nss.c
@@ -1798,9 +1798,13 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
 
 
   /* Force handshake on next I/O */
-  SSL_ResetHandshake(connssl->handle, /* asServer */ PR_FALSE);
+  if(SSL_ResetHandshake(connssl->handle, /* asServer */ PR_FALSE)
+      != SECSuccess)
+    goto error;
 
-  SSL_SetURL(connssl->handle, conn->host.name);
+  /* propagate hostname to the TLS layer */
+  if(SSL_SetURL(connssl->handle, conn->host.name) != SECSuccess)
+    goto error;
 
   return CURLE_OK;