summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2016-10-03 12:53:43 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2016-10-03 13:18:17 +0200
commit77b5cb53902087769cbfd801d46083525451b840 (patch)
tree4d7e1d8507f9981fc820541abe04ed836fb8cb76
parent79a3c6a772d9c2cb112a61a1e086aae98e59c26f (diff)
downloadgnutls-77b5cb53902087769cbfd801d46083525451b840.tar.gz
fix zero-termination in _gnutls_server_name_set_raw() for large server names
-rw-r--r--lib/ext/server_name.c9
-rw-r--r--lib/ext/server_name.h2
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/ext/server_name.c b/lib/ext/server_name.c
index 72c1387d3b..a5e01f890a 100644
--- a/lib/ext/server_name.c
+++ b/lib/ext/server_name.c
@@ -419,9 +419,12 @@ _gnutls_server_name_set_raw(gnutls_session_t session,
server_names = MAX_SERVER_NAME_EXTENSIONS;
priv->server_names[server_names - 1].type = type;
- memcpy(priv->server_names[server_names - 1].name, name,
- name_length);
- priv->server_names[server_names - 1].name[name_length] = 0;
+
+ if (name_length > 0) {
+ memcpy(priv->server_names[server_names - 1].name, name,
+ name_length);
+ priv->server_names[server_names - 1].name[name_length] = 0;
+ }
priv->server_names[server_names - 1].name_length = name_length;
priv->server_names_size = server_names;
diff --git a/lib/ext/server_name.h b/lib/ext/server_name.h
index 62daaf2754..a079a62066 100644
--- a/lib/ext/server_name.h
+++ b/lib/ext/server_name.h
@@ -25,7 +25,7 @@
#include <extensions.h>
typedef struct {
- uint8_t name[MAX_SERVER_NAME_SIZE];
+ uint8_t name[MAX_SERVER_NAME_SIZE+1];
unsigned name_length;
gnutls_server_name_type_t type;
} server_name_st;