Browse Source

Merge pull request #77011 from Faless/tls/fix_crashes_when_unavailable

[TLS] Fix crashes trying to use TLS when not available.
Rémi Verschelde 2 years ago
parent
commit
1c8b203f70
3 changed files with 6 additions and 1 deletions
  1. 1 0
      core/io/http_client_tcp.cpp
  2. 3 1
      modules/websocket/wsl_peer.cpp
  3. 2 0
      thirdparty/enet/godot.cpp

+ 1 - 0
core/io/http_client_tcp.cpp

@@ -60,6 +60,7 @@ Error HTTPClientTCP::connect_to_host(const String &p_host, int p_port, Ref<TLSOp
 	}
 	}
 
 
 	ERR_FAIL_COND_V(tls_options.is_valid() && tls_options->is_server(), ERR_INVALID_PARAMETER);
 	ERR_FAIL_COND_V(tls_options.is_valid() && tls_options->is_server(), ERR_INVALID_PARAMETER);
+	ERR_FAIL_COND_V_MSG(tls_options.is_valid() && !StreamPeerTLS::is_available(), ERR_UNAVAILABLE, "HTTPS is not available in this build.");
 	ERR_FAIL_COND_V(conn_host.length() < HOST_MIN_LEN, ERR_INVALID_PARAMETER);
 	ERR_FAIL_COND_V(conn_host.length() < HOST_MIN_LEN, ERR_INVALID_PARAMETER);
 
 
 	if (conn_port < 0) {
 	if (conn_port < 0) {

+ 3 - 1
modules/websocket/wsl_peer.cpp

@@ -332,7 +332,7 @@ void WSLPeer::_do_client_handshake() {
 		if (connection == tcp) {
 		if (connection == tcp) {
 			// Start SSL handshake
 			// Start SSL handshake
 			tls = Ref<StreamPeerTLS>(StreamPeerTLS::create());
 			tls = Ref<StreamPeerTLS>(StreamPeerTLS::create());
-			ERR_FAIL_COND_MSG(tls.is_null(), "SSL is not available in this build.");
+			ERR_FAIL_COND(tls.is_null());
 			if (tls->connect_to_stream(tcp, requested_host, tls_options) != OK) {
 			if (tls->connect_to_stream(tcp, requested_host, tls_options) != OK) {
 				close(-1);
 				close(-1);
 				return; // Error.
 				return; // Error.
@@ -501,6 +501,8 @@ Error WSLPeer::connect_to_url(const String &p_url, Ref<TLSOptions> p_options) {
 		path = "/";
 		path = "/";
 	}
 	}
 
 
+	ERR_FAIL_COND_V_MSG(use_tls && !StreamPeerTLS::is_available(), ERR_UNAVAILABLE, "WSS is not available in this build.");
+
 	requested_url = p_url;
 	requested_url = p_url;
 	requested_host = host;
 	requested_host = host;
 
 

+ 2 - 0
thirdparty/enet/godot.cpp

@@ -436,6 +436,7 @@ ENetSocket enet_socket_create(ENetSocketType type) {
 }
 }
 
 
 int enet_host_dtls_server_setup(ENetHost *host, void *p_options) {
 int enet_host_dtls_server_setup(ENetHost *host, void *p_options) {
+	ERR_FAIL_COND_V_MSG(!DTLSServer::is_available(), -1, "DTLS server is not available in this build.");
 	ENetGodotSocket *sock = (ENetGodotSocket *)host->socket;
 	ENetGodotSocket *sock = (ENetGodotSocket *)host->socket;
 	if (!sock->can_upgrade()) {
 	if (!sock->can_upgrade()) {
 		return -1;
 		return -1;
@@ -446,6 +447,7 @@ int enet_host_dtls_server_setup(ENetHost *host, void *p_options) {
 }
 }
 
 
 int enet_host_dtls_client_setup(ENetHost *host, const char *p_for_hostname, void *p_options) {
 int enet_host_dtls_client_setup(ENetHost *host, const char *p_for_hostname, void *p_options) {
+	ERR_FAIL_COND_V_MSG(!PacketPeerDTLS::is_available(), -1, "DTLS is not available in this build.");
 	ENetGodotSocket *sock = (ENetGodotSocket *)host->socket;
 	ENetGodotSocket *sock = (ENetGodotSocket *)host->socket;
 	if (!sock->can_upgrade()) {
 	if (!sock->can_upgrade()) {
 		return -1;
 		return -1;