Skip to content

Commit

Permalink
Merge pull request #23241 from Faless/lws_more_fix
Browse files Browse the repository at this point in the history
Remove unneeded strncpy in lws_client.
  • Loading branch information
akien-mga committed Oct 23, 2018
2 parents a36a99b + e6a0691 commit 841d62c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
3 changes: 3 additions & 0 deletions modules/websocket/emws_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ int EMWSServer::get_peer_port(int p_peer_id) const {
void EMWSServer::disconnect_peer(int p_peer_id, int p_code, String p_reason) {
}

void EMWSServer::poll() {
}

EMWSServer::EMWSServer() {
}

Expand Down
28 changes: 9 additions & 19 deletions modules/websocket/lws_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
#include "core/io/stream_peer_ssl.h"
#include "tls/mbedtls/wrapper/include/openssl/ssl.h"

#if defined(MINGW_ENABLED) || defined(_MSC_VER)
#define strncpy strncpy_s
#endif

Error LWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocols) {

ERR_FAIL_COND_V(context != NULL, FAILED);
Expand Down Expand Up @@ -80,26 +76,11 @@ Error LWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
ERR_FAIL_V(FAILED);
}

char abuf[1024];
char hbuf[1024];
char pbuf[2048];
String addr_str = (String)addr;
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)
i.protocol = _lws_ref->lws_names;
else
i.protocol = NULL;
i.address = abuf;
i.host = hbuf;
i.path = pbuf;
i.port = p_port;

if (p_ssl) {
i.ssl_connection = LCCSCF_USE_SSL;
Expand All @@ -109,7 +90,16 @@ Error LWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
i.ssl_connection = 0;
}

// This String needs to survive till we call lws_client_connect_via_info
String addr_str = (String)addr;

i.address = addr_str.ascii().get_data();
i.host = p_host.utf8().get_data();
i.path = p_path.utf8().get_data();
i.port = p_port;

lws_client_connect_via_info(&i);

return OK;
};

Expand Down

0 comments on commit 841d62c

Please sign in to comment.