Skip to content

Commit

Permalink
check return value of wolfSSL_set_fd
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Mar 25, 2016
1 parent 57ea1cd commit 6961696
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
16 changes: 12 additions & 4 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ int ClientBenchmarkConnections(WOLFSSL_CTX* ctx, char* host, word16 port,
if (benchResume)
wolfSSL_set_session(ssl, benchSession);
#endif
wolfSSL_set_fd(ssl, sockfd);
if (wolfSSL_set_fd(ssl, sockfd) != SSL_SUCCESS) {
err_sys("error in setting fd");
}
if (wolfSSL_connect(ssl) != SSL_SUCCESS)
err_sys("SSL_connect failed");

Expand Down Expand Up @@ -213,7 +215,9 @@ int ClientBenchmarkThroughput(WOLFSSL_CTX* ctx, char* host, word16 port,
if (ssl == NULL)
err_sys("unable to get SSL object");
tcp_connect(&sockfd, host, port, doDTLS, ssl);
wolfSSL_set_fd(ssl, sockfd);
if (wolfSSL_set_fd(ssl, sockfd) != SSL_SUCCESS) {
err_sys("error in setting fd");
}
if (wolfSSL_connect(ssl) == SSL_SUCCESS) {
/* Perform throughput test */
char *tx_buffer, *rx_buffer;
Expand Down Expand Up @@ -1140,7 +1144,9 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
#endif

tcp_connect(&sockfd, host, port, doDTLS, ssl);
wolfSSL_set_fd(ssl, sockfd);
if (wolfSSL_set_fd(ssl, sockfd) != SSL_SUCCESS) {
err_sys("error in setting fd");
}
#ifdef HAVE_CRL
if (disableCRL == 0) {
if (wolfSSL_EnableCRL(ssl, WOLFSSL_CRL_CHECKALL) != SSL_SUCCESS)
Expand Down Expand Up @@ -1292,7 +1298,9 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
#endif
}
tcp_connect(&sockfd, host, port, doDTLS, sslResume);
wolfSSL_set_fd(sslResume, sockfd);
if (wolfSSL_set_fd(sslResume, sockfd) != SSL_SUCCESS) {
err_sys("error in setting fd");
}
#ifdef HAVE_ALPN
if (alpnList != NULL) {
printf("ALPN accepted protocols list : %s\n", alpnList);
Expand Down
4 changes: 3 additions & 1 deletion examples/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,9 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
doDTLS, serverReadyFile ? 1 : 0, doListen);
doListen = 0; /* Don't listen next time */

SSL_set_fd(ssl, clientfd);
if (SSL_set_fd(ssl, clientfd) != SSL_SUCCESS) {
err_sys("error in setting fd");
}

#ifdef HAVE_ALPN
if (alpnList != NULL) {
Expand Down
4 changes: 3 additions & 1 deletion input
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ int main(int argc, char** argv)

ssl = SSL_new(ctx);

SSL_set_fd(ssl, sockfd);
if (SSL_set_fd(ssl, sockfd) != SSL_SUCCESS)
err_sys("can't set ssl fd");

if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");

while (fgets(send, sizeof(send), fin)) {
Expand Down
4 changes: 3 additions & 1 deletion mqx/wolfssl_client/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ void client_test(void)
if ( (ssl = wolfSSL_new(ctx)) == NULL)
err_sys("wolfSSL_new failed");

wolfSSL_set_fd(ssl, sockfd);
ret = wolfSSL_set_fd(ssl, sockfd);
if (ret != SSL_SUCCESS)
err_sys("wolfSSL_set_fd failed");

ret = wolfSSL_connect(ssl);
if (ret != SSL_SUCCESS)
Expand Down
3 changes: 2 additions & 1 deletion swig/wolfssl_adds.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ int wolfSSL_swig_connect(WOLFSSL* ssl, const char* server, int port)
int ret = tcp_connect(&sockfd, server, port);
if (ret != 0) return ret;

wolfSSL_set_fd(ssl, sockfd);
ret = wolfSSL_set_fd(ssl, sockfd);
if (ret != SSL_SUCCESS) return ret;

return wolfSSL_connect(ssl);
}
Expand Down
15 changes: 11 additions & 4 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,10 @@ static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args)
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 1);
CloseSocket(sockfd);

wolfSSL_set_fd(ssl, clientfd);
if (wolfSSL_set_fd(ssl, clientfd) != SSL_SUCCESS) {
/*err_sys("SSL_set_fd failed");*/
goto done;
}

#ifdef NO_PSK
#if !defined(NO_FILESYSTEM) && !defined(NO_DH)
Expand Down Expand Up @@ -649,7 +652,11 @@ static void test_client_nofail(void* args)

ssl = wolfSSL_new(ctx);
tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port, 0, ssl);
wolfSSL_set_fd(ssl, sockfd);
if (wolfSSL_set_fd(ssl, sockfd) != SSL_SUCCESS) {
/*err_sys("SSL_set_fd failed");*/
goto done2;
}

if (wolfSSL_connect(ssl) != SSL_SUCCESS)
{
int err = wolfSSL_get_error(ssl, 0);
Expand Down Expand Up @@ -739,7 +746,7 @@ static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 1);
CloseSocket(sfd);

wolfSSL_set_fd(ssl, cfd);
AssertIntEQ(SSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));

#ifdef NO_PSK
#if !defined(NO_FILESYSTEM) && !defined(NO_DH)
Expand Down Expand Up @@ -831,7 +838,7 @@ static void run_wolfssl_client(void* args)

ssl = wolfSSL_new(ctx);
tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port, 0, ssl);
wolfSSL_set_fd(ssl, sfd);
AssertIntEQ(SSL_SUCCESS, wolfSSL_set_fd(ssl, sfd));

if (callbacks->ssl_ready)
callbacks->ssl_ready(ssl);
Expand Down

0 comments on commit 6961696

Please sign in to comment.