From: Christian Grothoff Date: Sun, 22 Jan 2017 22:25:25 +0000 (+0100) Subject: simplify check_data logic X-Git-Tag: taler-0.2.1~348 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=22141e7eb07d6331ad1c2548032c2de014f33383;p=oweals%2Fgnunet.git simplify check_data logic --- diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c index 76bc4ec48..cb8eab2fe 100644 --- a/src/cadet/gnunet-service-cadet-new.c +++ b/src/cadet/gnunet-service-cadet-new.c @@ -629,30 +629,33 @@ check_data (void *cls, const char *buf; struct GNUNET_MessageHeader pa; + /* FIXME: what is the format we shall allow for @a msg? + ONE payload item or multiple? Seems current cadet_api + at least in theory allows more than one. Next-gen + cadet_api will likely no more. + + Regardless, the multi-message check below should pass, + albeit it does not :-(. */ /* Sanity check for message size */ payload_size = ntohs (msg->header.size) - sizeof (*msg); - if ( (payload_size < sizeof (struct GNUNET_MessageHeader)) || - (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < payload_size) ) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } buf = (const char *) &msg[1]; - do { + while (payload_size >= sizeof (struct GNUNET_MessageHeader)) + { /* need to memcpy() for alignment */ GNUNET_memcpy (&pa, buf, sizeof (pa)); payload_claimed_size = ntohs (pa.size); if ( (payload_size < payload_claimed_size) || - (0 == payload_claimed_size) ) + (payload_claimed_size < sizeof (struct GNUNET_MessageHeader)) || + (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < payload_claimed_size) ) { GNUNET_break_op (0); return GNUNET_SYSERR; } payload_size -= payload_claimed_size; buf += payload_claimed_size; - } while (payload_size >= sizeof (struct GNUNET_MessageHeader)); + } if (0 != payload_size) { GNUNET_break_op (0); diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c index 42565d276..b92c4eaf5 100644 --- a/src/cadet/gnunet-service-cadet-new_channel.c +++ b/src/cadet/gnunet-service-cadet-new_channel.c @@ -1294,7 +1294,7 @@ GCCH_handle_local_data (struct CadetChannel *ch, if (GNUNET_NO == ch->client_allowed) { - GNUNET_break_op (0); + GNUNET_break (0); return GNUNET_SYSERR; } ch->client_allowed = GNUNET_NO; diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index a411b41bc..b19963bba 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c @@ -536,7 +536,9 @@ tmt_rdy (void *cls, size_t size, void *buf) long id = (long) cls; unsigned int counter; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy on %ld, filling buffer\n", id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "tmt_rdy on %ld, filling buffer\n", + id); if (0 == id) th = NULL; else if ((peers_requested - 1) == id) @@ -545,7 +547,8 @@ tmt_rdy (void *cls, size_t size, void *buf) GNUNET_assert (0); counter = get_expected_target () == id ? ack_sent : data_sent; msg_size = size_payload + counter; - if (size < msg_size || NULL == buf) + if ( (size < msg_size) || + (NULL == buf) ) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "size %u, buf %p, data_sent %u, ack_received %u\n", @@ -569,7 +572,8 @@ tmt_rdy (void *cls, size_t size, void *buf) if (SPEED_ACK == test) data_sent++; } - else if (SPEED == test || SPEED_ACK == test) + else if ( (SPEED == test) || + (SPEED_ACK == test) ) { if (get_expected_target() == id) ack_sent++; @@ -580,9 +584,11 @@ tmt_rdy (void *cls, size_t size, void *buf) " Sent message %u size %u\n", counter, (unsigned int) msg_size); - if (data_sent < TOTAL_PACKETS && SPEED == test) + if ( (data_sent < TOTAL_PACKETS) && + (SPEED == test) ) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Scheduling message %d\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + " Scheduling message %d\n", counter + 1); data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL); }