From 98cb8d09a583c72ed50cfa0f2487e65c38ec3ad0 Mon Sep 17 00:00:00 2001 From: "Fabio M. Di Nitto" Date: Sun, 11 Sep 2016 14:27:01 +0200 Subject: [PATCH] [send/recv] Fix checks for knet_send_sync and move sync test earlier Signed-off-by: Fabio M. Di Nitto --- libknet/threads_send_recv.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/libknet/threads_send_recv.c b/libknet/threads_send_recv.c index 849907d..e7ef03c 100644 --- a/libknet/threads_send_recv.c +++ b/libknet/threads_send_recv.c @@ -192,6 +192,16 @@ static int _parse_recv_from_sock(knet_handle_t knet_h, int buf_idx, ssize_t inle break; } + if (sync) { + if ((bcast) || + ((!bcast) && (dst_host_ids_entries_temp > 1))) { + log_debug(knet_h, KNET_SUB_SEND_T, "knet_send_sync is only supported with unicast packets for one destination"); + savederrno = E2BIG; + err = -1; + goto out_unlock; + } + } + /* * check destinations hosts before spending time * in fragmenting/encrypting packets to save @@ -232,16 +242,6 @@ static int _parse_recv_from_sock(knet_handle_t knet_h, int buf_idx, ssize_t inle } } - if (sync) { - if ((send_mcast) || - ((!bcast) && (dst_host_ids_entries > 1))) { - log_debug(knet_h, KNET_SUB_SEND_T, "knet_send_sync is only supported with unicast packets for one destination"); - savederrno = E2BIG; - err = -1; - goto out_unlock; - } - } - if (!knet_h->data_mtu) { /* * using MIN_MTU_V4 for data mtu is not completely accurate but safe enough @@ -412,7 +412,17 @@ int knet_send_sync(knet_handle_t knet_h, const char *buff, const size_t buff_len return -1; } - if ((buff_len <= 0) || (buff_len > KNET_MAX_PACKET_SIZE)) { + if (buff_len <= 0) { + errno = EINVAL; + return -1; + } + + if (buff_len > KNET_MAX_PACKET_SIZE) { + errno = EINVAL; + return -1; + } + + if (channel < 0) { errno = EINVAL; return -1; } -- 2.39.5