[PATCH] server_name: Return the actual required buffer size if the buffer is too small

Martin Storsjo martin at martin.st
Wed Oct 31 14:44:35 CET 2012


Since we require space for the null termination, include this in
the info returned if the caller provided a too small buffer.
Otherwise, if the caller allocated a buffer of exactly the suggested
size, it would still be too small.
---
 lib/ext/server_name.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/ext/server_name.c b/lib/ext/server_name.c
index ad449ad..de5fbe5 100644
--- a/lib/ext/server_name.c
+++ b/lib/ext/server_name.c
@@ -312,27 +312,27 @@ gnutls_server_name_get (gnutls_session_t session, void *data,
 
   if (*data_length >            /* greater since we need one extra byte for the null */
       priv->server_names[indx].name_length)
     {
       *data_length = priv->server_names[indx].name_length;
       memcpy (data, priv->server_names[indx].name, *data_length);
 
       if (*type == GNUTLS_NAME_DNS)     /* null terminate */
         _data[(*data_length)] = 0;
 
     }
   else
     {
-      *data_length = priv->server_names[indx].name_length;
+      *data_length = priv->server_names[indx].name_length + 1;
       return GNUTLS_E_SHORT_MEMORY_BUFFER;
     }
 
   return 0;
 }
 
 /**
  * gnutls_server_name_set:
  * @session: is a #gnutls_session_t structure.
  * @type: specifies the indicator type
  * @name: is a string that contains the server name.
  * @name_length: holds the length of name
  *
-- 
1.7.9.4





More information about the Gnutls-devel mailing list