Skip to content

Commit

Permalink
api.c message type cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruby Martin committed Jan 28, 2025
1 parent 04d342e commit 8e3b335
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,11 @@ int test_memio_setup(struct test_memio_ctx *ctx,
}
#endif

#ifdef USE_WINDOWS_API
#define MESSAGE_TYPE_CAST char*
#else
#define MESSAGE_TYPE_CAST void*
#endif
/*----------------------------------------------------------------------------*
| BIO with fixed read/write size
*----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -8389,7 +8394,7 @@ static THREAD_RETURN WOLFSSL_THREAD test_server_loop(void* args)
if (!sharedCtx)
wolfSSL_CTX_free(ctx);

if (clientfd >= 0)
if (clientfd != SOCKET_INVALID)
CloseSocket(clientfd);

#ifdef WOLFSSL_TIRTOS
Expand Down Expand Up @@ -76214,7 +76219,7 @@ static int test_wolfSSL_TXT_DB(void)

/* Test index */
ExpectIntEQ(TXT_DB_create_index(db, 3, NULL,
(wolf_sk_hash_cb)(long unsigned int)TXT_DB_hash,
(wolf_sk_hash_cb)TXT_DB_hash,
(wolf_lh_compare_cb)TXT_DB_cmp), 1);
ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
fields[3] = "12DA";
Expand Down Expand Up @@ -90343,10 +90348,10 @@ static void test_wolfSSL_dtls_plaintext_client(WOLFSSL* ssl)
AssertIntGE(fd, 0);
generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 0);
/* Server should ignore this datagram */
AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
AssertIntEQ(send(fd, (MESSAGE_TYPE_CAST)ch, sizeof(ch), 0), sizeof(ch));
generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 10000);
/* Server should ignore this datagram */
AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
AssertIntEQ(send(fd, (MESSAGE_TYPE_CAST)ch, sizeof(ch), 0), sizeof(ch));

AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
Expand Down Expand Up @@ -90457,7 +90462,7 @@ static void test_wolfSSL_dtls12_fragments_spammer(WOLFSSL* ssl)
delay.tv_nsec = 10000000; /* wait 0.01 seconds */
c32toa(seq_number, b + seq_offset);
c16toa(msg_number, b + msg_offset);
ret = (int)send(fd, b, 55, 0);
ret = (int)send(fd, (MESSAGE_TYPE_CAST)b, 55, 0);
nanosleep(&delay, NULL);
}
}
Expand Down Expand Up @@ -90502,7 +90507,7 @@ static void test_wolfSSL_dtls13_fragments_spammer(WOLFSSL* ssl)
c16toa(msg_number, b + msg_offset);
sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b,
(int)idx, handshake, 0, 0, 0);
ret = (int)send(fd, sendBuf, (size_t)sendSz, 0);
ret = (int)send(fd, (MESSAGE_TYPE_CAST)sendBuf, (size_t)sendSz, 0);
nanosleep(&delay, NULL);
}
}
Expand Down Expand Up @@ -90576,7 +90581,7 @@ static void test_wolfSSL_dtls_send_alert(WOLFSSL* ssl)

fd = wolfSSL_get_wfd(ssl);
AssertIntGE(fd, 0);
ret = (int)send(fd, alert_msg, sizeof(alert_msg), 0);
ret = (int)send(fd, (MESSAGE_TYPE_CAST)alert_msg, sizeof(alert_msg), 0);
AssertIntGT(ret, 0);
}

Expand Down Expand Up @@ -90647,7 +90652,7 @@ static void test_wolfSSL_send_bad_record(WOLFSSL* ssl)

fd = wolfSSL_get_wfd(ssl);
AssertIntGE(fd, 0);
ret = (int)send(fd, bad_msg, sizeof(bad_msg), 0);
ret = (int)send(fd, (MESSAGE_TYPE_CAST)bad_msg, sizeof(bad_msg), 0);
AssertIntEQ(ret, sizeof(bad_msg));
ret = wolfSSL_write(ssl, "badrecordtest", sizeof("badrecordtest"));
AssertIntEQ(ret, sizeof("badrecordtest"));
Expand Down Expand Up @@ -90728,7 +90733,7 @@ static byte test_AEAD_done = 0;

static int test_AEAD_cbiorecv(WOLFSSL *ssl, char *buf, int sz, void *ctx)
{
int ret = (int)recv(wolfSSL_get_fd(ssl), buf, sz, 0);
int ret = (int)recv(wolfSSL_get_fd(ssl), (MESSAGE_TYPE_CAST)buf, sz, 0);
if (ret > 0) {
if (test_AEAD_fail_decryption) {
/* Modify the packet to trigger a decryption failure */
Expand Down Expand Up @@ -90974,10 +90979,10 @@ static void test_wolfSSL_dtls_send_ch(WOLFSSL* ssl)

fd = wolfSSL_get_wfd(ssl);
AssertIntGE(fd, 0);
ret = (int)send(fd, ch_msg, sizeof(ch_msg), 0);
ret = (int)send(fd, (MESSAGE_TYPE_CAST)ch_msg, sizeof(ch_msg), 0);
AssertIntGT(ret, 0);
/* consume the HRR otherwise handshake will fail */
ret = (int)recv(fd, ch_msg, sizeof(ch_msg), 0);
ret = (int)recv(fd, (MESSAGE_TYPE_CAST)ch_msg, sizeof(ch_msg), 0);
AssertIntGT(ret, 0);
}

Expand Down Expand Up @@ -91045,10 +91050,10 @@ static void test_wolfSSL_dtls_send_ch_with_invalid_cookie(WOLFSSL* ssl)
};

fd = wolfSSL_get_wfd(ssl);
ret = (int)send(fd, ch_msh_invalid_cookie, sizeof(ch_msh_invalid_cookie), 0);
ret = (int)send(fd, (MESSAGE_TYPE_CAST)ch_msh_invalid_cookie, sizeof(ch_msh_invalid_cookie), 0);
AssertIntGT(ret, 0);
/* should reply with an illegal_parameter reply */
ret = (int)recv(fd, alert_reply, sizeof(alert_reply), 0);
ret = (int)recv(fd, (MESSAGE_TYPE_CAST)alert_reply, sizeof(alert_reply), 0);
AssertIntEQ(ret, sizeof(expected_alert_reply));
AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply, sizeof(expected_alert_reply)), 0);
}
Expand Down Expand Up @@ -97619,7 +97624,8 @@ static int test_dtls_msg_from_other_peer(void)
* !defined(SINGLE_THREADED) && !defined(NO_RSA) */
#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_IPV6) && \
!defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) \
&& !defined(USE_WINDOWS_API)
static int test_dtls_ipv6_check(void)
{
EXPECT_DECLS;
Expand Down

0 comments on commit 8e3b335

Please sign in to comment.