Explorar o código

Fix LWSClient connect_to_host string termination.

Coming from strncpy might get you a non-NULL terminated buffer.
The solution, if you accept trunction, is to give one less byte to
strncpy and manually set the last char in the buffer to '\0'.
If the source string is shorter, than the buffer is padded with '\0'
automatically.
Fabio Alessandrelli %!s(int64=7) %!d(string=hai) anos
pai
achega
d65afb2c74
Modificáronse 1 ficheiros con 6 adicións e 3 borrados
  1. 6 3
      modules/websocket/lws_client.cpp

+ 6 - 3
modules/websocket/lws_client.cpp

@@ -80,9 +80,12 @@ Error LWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
 	char hbuf[1024];
 	char pbuf[2048];
 	String addr_str = (String)addr;
-	strncpy(abuf, addr_str.ascii().get_data(), 1024);
-	strncpy(hbuf, p_host.utf8().get_data(), 1024);
-	strncpy(pbuf, p_path.utf8().get_data(), 2048);
+	strncpy(abuf, addr_str.ascii().get_data(), 1023);
+	abuf[1023] = '\0';
+	strncpy(hbuf, p_host.utf8().get_data(), 1023);
+	hbuf[1023] = '\0';
+	strncpy(pbuf, p_path.utf8().get_data(), 2047);
+	pbuf[2047] = '\0';
 
 	i.context = context;
 	if (p_protocols.size() > 0)