From 4586cfcb4bab090c3f7d8e9e0dfae147395d0e1a Mon Sep 17 00:00:00 2001 From: Alexandru-Ioan Pop Date: Fri, 19 May 2017 22:48:22 +0100 Subject: [PATCH] Terminate websocket strings Explicitly terminate the field strings when registering a websocket client. --- core/net/ipv6/websocket-http-client.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/net/ipv6/websocket-http-client.c b/core/net/ipv6/websocket-http-client.c index ab9b75f92..865bf1887 100644 --- a/core/net/ipv6/websocket-http-client.c +++ b/core/net/ipv6/websocket-http-client.c @@ -228,21 +228,23 @@ websocket_http_client_register(struct websocket_http_client_state *s, return -1; } strncpy(s->host, host, sizeof(s->host)); + s->host[sizeof(s->host) - 1] = '\0'; if(file == NULL) { return -1; } strncpy(s->file, file, sizeof(s->file)); + s->file[sizeof(s->file) - 1] = '\0'; if(subprotocol == NULL) { return -1; } strncpy(s->subprotocol, subprotocol, sizeof(s->subprotocol)); + s->subprotocol[sizeof(s->subprotocol) - 1] = '\0'; - if(header == NULL) { - strncpy(s->header, "", sizeof(s->header)); - } else { - strncpy(s->header, header, sizeof(s->header)); + memset(s->header, 0, sizeof(s->header)); + if(header != NULL) { + strncpy(s->header, header, sizeof(s->header) - 1); } if(port == 0) {