Skip to content

Commit

Permalink
Remove SSL_NEW() and SSL_FREE()
Browse files Browse the repository at this point in the history
Do not overload functions from OpenSSL.
  • Loading branch information
bradleythughes committed Mar 7, 2019
1 parent 043b102 commit e781060
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
16 changes: 8 additions & 8 deletions src/apps/relay/dtls_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,13 @@ static ioa_socket_handle dtls_server_input_handler(dtls_listener_relay_server_ty
#if DTLSv1_2_SUPPORTED
if(get_dtls_version(ioa_network_buffer_data(nbh),
(int)ioa_network_buffer_get_size(nbh)) == 1) {
connecting_ssl = SSL_NEW(server->dtls_ctx_v1_2);
connecting_ssl = SSL_new(server->dtls_ctx_v1_2);
} else {
connecting_ssl = SSL_NEW(server->dtls_ctx);
connecting_ssl = SSL_new(server->dtls_ctx);
}
#else
{
connecting_ssl = SSL_NEW(server->dtls_ctx);
connecting_ssl = SSL_new(server->dtls_ctx);
}
#endif

Expand All @@ -315,7 +315,7 @@ static ioa_socket_handle dtls_server_input_handler(dtls_listener_relay_server_ty
SSL_set_shutdown(connecting_ssl, SSL_RECEIVED_SHUTDOWN);
SSL_shutdown(connecting_ssl);
}
SSL_FREE(connecting_ssl);
SSL_free(connecting_ssl);
}

return rc;
Expand Down Expand Up @@ -573,13 +573,13 @@ static int create_new_connected_udp_socket(
#if DTLSv1_2_SUPPORTED
if(get_dtls_version(ioa_network_buffer_data(server->sm.m.sm.nd.nbh),
(int)ioa_network_buffer_get_size(server->sm.m.sm.nd.nbh)) == 1) {
connecting_ssl = SSL_NEW(server->dtls_ctx_v1_2);
connecting_ssl = SSL_new(server->dtls_ctx_v1_2);
} else {
connecting_ssl = SSL_NEW(server->dtls_ctx);
connecting_ssl = SSL_new(server->dtls_ctx);
}
#else
{
connecting_ssl = SSL_NEW(server->dtls_ctx);
connecting_ssl = SSL_new(server->dtls_ctx);
}
#endif

Expand All @@ -597,7 +597,7 @@ static int create_new_connected_udp_socket(
SSL_set_shutdown(connecting_ssl, SSL_RECEIVED_SHUTDOWN);
SSL_shutdown(connecting_ssl);
}
SSL_FREE(connecting_ssl);
SSL_free(connecting_ssl);
IOA_CLOSE_SOCKET(ret);
return -1;
}
Expand Down
20 changes: 10 additions & 10 deletions src/apps/relay/ns_ioalib_engine_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ static void close_socket_net_data(ioa_socket_handle s)
log_socket_event(s, "SSL shutdown received, socket to be closed",0);
}
}
SSL_FREE(s->ssl);
SSL_free(s->ssl);
}

if (s->fd >= 0) {
Expand Down Expand Up @@ -2240,25 +2240,25 @@ static int socket_input_worker(ioa_socket_handle s)
#if TLSv1_2_SUPPORTED
case TURN_TLS_v1_2:
if(s->e->tls_ctx_v1_2) {
set_socket_ssl(s,SSL_NEW(s->e->tls_ctx_v1_2));
set_socket_ssl(s,SSL_new(s->e->tls_ctx_v1_2));
}
break;
#endif
#if TLSv1_1_SUPPORTED
case TURN_TLS_v1_1:
if(s->e->tls_ctx_v1_1) {
set_socket_ssl(s,SSL_NEW(s->e->tls_ctx_v1_1));
set_socket_ssl(s,SSL_new(s->e->tls_ctx_v1_1));
}
break;
#endif
case TURN_TLS_v1_0:
if(s->e->tls_ctx_v1_0) {
set_socket_ssl(s,SSL_NEW(s->e->tls_ctx_v1_0));
set_socket_ssl(s,SSL_new(s->e->tls_ctx_v1_0));
}
break;
default:
if(s->e->tls_ctx_ssl23) {
set_socket_ssl(s,SSL_NEW(s->e->tls_ctx_ssl23));
set_socket_ssl(s,SSL_new(s->e->tls_ctx_ssl23));
} else {
s->tobeclosed = 1;
return 0;
Expand Down Expand Up @@ -2308,25 +2308,25 @@ static int socket_input_worker(ioa_socket_handle s)
#if TLSv1_2_SUPPORTED
case TURN_TLS_v1_2:
if(s->e->tls_ctx_v1_2) {
set_socket_ssl(s,SSL_NEW(s->e->tls_ctx_v1_2));
set_socket_ssl(s,SSL_new(s->e->tls_ctx_v1_2));
}
break;
#endif
#if TLSv1_1_SUPPORTED
case TURN_TLS_v1_1:
if(s->e->tls_ctx_v1_1) {
set_socket_ssl(s,SSL_NEW(s->e->tls_ctx_v1_1));
set_socket_ssl(s,SSL_new(s->e->tls_ctx_v1_1));
}
break;
#endif
case TURN_TLS_v1_0:
if(s->e->tls_ctx_v1_0) {
set_socket_ssl(s,SSL_NEW(s->e->tls_ctx_v1_0));
set_socket_ssl(s,SSL_new(s->e->tls_ctx_v1_0));
}
break;
default:
if(s->e->tls_ctx_ssl23) {
set_socket_ssl(s,SSL_NEW(s->e->tls_ctx_ssl23));
set_socket_ssl(s,SSL_new(s->e->tls_ctx_ssl23));
} else {
s->tobeclosed = 1;
return 0;
Expand Down Expand Up @@ -3317,7 +3317,7 @@ int register_callback_on_ioa_socket(ioa_engine_handle e, ioa_socket_handle s, in
#if TLS_SUPPORTED
if(!(s->ssl)) {
//??? how we can get to this point ???
set_socket_ssl(s,SSL_NEW(e->tls_ctx_ssl23));
set_socket_ssl(s,SSL_new(e->tls_ctx_ssl23));
s->bev = bufferevent_openssl_socket_new(s->e->event_base,
s->fd,
s->ssl,
Expand Down
8 changes: 4 additions & 4 deletions src/apps/uclient/startuclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static SSL* tls_connect(ioa_socket_raw fd, ioa_addr *remote_addr, int *try_again

SSL *ssl;

ssl = SSL_NEW(root_tls_ctx[ctxtype]);
ssl = SSL_new(root_tls_ctx[ctxtype]);

#if ALPN_SUPPORTED
SSL_set_alpn_protos(ssl, kALPNProtos, kALPNProtosLen);
Expand Down Expand Up @@ -161,7 +161,7 @@ static SSL* tls_connect(ioa_socket_raw fd, ioa_addr *remote_addr, int *try_again
(int)ERR_get_error(), ERR_error_string(ERR_get_error(), buf), (int)SSL_get_error(ssl, rc));
if(connect_cycle<MAX_TLS_CYCLES) {
if(try_again) {
SSL_FREE(ssl);
SSL_free(ssl);
*try_again = 1;
return NULL;
}
Expand Down Expand Up @@ -600,7 +600,7 @@ static int clnet_allocate(int verbose,
int close_socket = (int)(random()%2);
if(ssl && !close_socket) {
SSL_shutdown(ssl);
SSL_FREE(ssl);
SSL_free(ssl);
fd = -1;
} else if(fd>=0) {
close(fd);
Expand All @@ -624,7 +624,7 @@ static int clnet_allocate(int verbose,

if(ssl) {
SSL_shutdown(ssl);
SSL_FREE(ssl);
SSL_free(ssl);
} else if(fd>=0) {
close(fd);
}
Expand Down
8 changes: 4 additions & 4 deletions src/apps/uclient/uclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static void uc_delete_session_elem_data(app_ur_session* cdi) {
SSL_shutdown(cdi->pinfo.tcp_conn[i]->tcp_data_ssl);
}
if(cdi->pinfo.tcp_conn[i]->tcp_data_ssl) {
SSL_FREE(cdi->pinfo.tcp_conn[i]->tcp_data_ssl);
SSL_free(cdi->pinfo.tcp_conn[i]->tcp_data_ssl);
}
if(cdi->pinfo.tcp_conn[i]->tcp_data_fd>=0) {
socket_closesocket(cdi->pinfo.tcp_conn[i]->tcp_data_fd);
Expand All @@ -166,7 +166,7 @@ static void uc_delete_session_elem_data(app_ur_session* cdi) {
}
}
if(cdi->pinfo.ssl) {
SSL_FREE(cdi->pinfo.ssl);
SSL_free(cdi->pinfo.ssl);
}
if(cdi->pinfo.fd>=0) {
socket_closesocket(cdi->pinfo.fd);
Expand Down Expand Up @@ -1022,7 +1022,7 @@ static int start_client(const char *remote_address, int port,
clnet_info_rtcp, &chnum_rtcp);

if(clnet_info_probe.ssl) {
SSL_FREE(clnet_info_probe.ssl);
SSL_free(clnet_info_probe.ssl);
clnet_info_probe.fd = -1;
} else if(clnet_info_probe.fd != -1) {
socket_closesocket(clnet_info_probe.fd);
Expand Down Expand Up @@ -1126,7 +1126,7 @@ static int start_c2c(const char *remote_address, int port,
clnet_info2_rtcp, &chnum2_rtcp);

if(clnet_info_probe.ssl) {
SSL_FREE(clnet_info_probe.ssl);
SSL_free(clnet_info_probe.ssl);
clnet_info_probe.fd = -1;
} else if(clnet_info_probe.fd != -1) {
socket_closesocket(clnet_info_probe.fd);
Expand Down
5 changes: 0 additions & 5 deletions src/ns_turn_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,14 @@ static inline u64bits _ioa_ntoh64(u64bits v)
#define debug_ptr_del(ptr) debug_ptr_del_func((ptr),__FUNCTION__,__LINE__)
#define tm_print() tm_print_func()

#define SSL_NEW(ctx) ((SSL*)debug_ptr_add(SSL_new(ctx)))

#else

#define debug_ptr_add(ptr)
#define debug_ptr_del(ptr)
#define tm_print()

#define SSL_NEW(ctx) SSL_new(ctx)

#endif

#define SSL_FREE(ssl) do { debug_ptr_del(ssl); SSL_free(ssl); ssl = NULL; } while(0)
#define BUFFEREVENT_FREE(be) do { if(be) { debug_ptr_del(be); bufferevent_flush(be,EV_READ|EV_WRITE,BEV_FLUSH); bufferevent_disable(be,EV_READ|EV_WRITE); bufferevent_free(be); be = NULL;} } while(0)

#define turn_time() ((turn_time_t)time(NULL))
Expand Down

0 comments on commit e781060

Please sign in to comment.