From 5aa499206cec322f918d51d157da9b8af5beed22 Mon Sep 17 00:00:00 2001 From: Jakub Adam Date: Sat, 27 Oct 2018 01:10:22 +0200 Subject: udp-turn: don't re-iterate incoming TURN control messages After being parsed, a TURN control message turns into a NiceInputMessage with zero length. Such message doesn't increment the iteration counter i and so is re-processed in the next iteration, which detects right away that message->length == 0 and continues to the next element in recv_messages. Thus, n_valid_messages variable serves no real purpose and to achieve the same result we can simply increment the iteration counter after each message. --- socket/udp-turn.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/socket/udp-turn.c b/socket/udp-turn.c index 15b41f2..d2c2cb5 100644 --- a/socket/udp-turn.c +++ b/socket/udp-turn.c @@ -340,7 +340,6 @@ socket_recv_messages (NiceSocket *sock, gint n_messages; guint i; gboolean error = FALSE; - guint n_valid_messages; /* Make sure socket has not been freed: */ g_assert (sock->priv != NULL); @@ -360,7 +359,7 @@ socket_recv_messages (NiceSocket *sock, * Implementing such a path means rewriting the TURN parser (and hence the * STUN message code) to operate on vectors of buffers, rather than a * monolithic buffer. */ - for (i = 0; i < (guint) n_messages; i += n_valid_messages) { + for (i = 0; i < (guint) n_messages; ++i) { NiceInputMessage *message = &recv_messages[i]; NiceSocket *dummy; NiceAddress from; @@ -369,8 +368,6 @@ socket_recv_messages (NiceSocket *sock, gint parsed_buffer_length; gboolean allocated_buffer = FALSE; - n_valid_messages = 1; - if (message->length == 0) continue; @@ -397,13 +394,11 @@ socket_recv_messages (NiceSocket *sock, if (parsed_buffer_length < 0) { error = TRUE; - } else if (parsed_buffer_length == 0) { - /* A TURN control message which needs ignoring. Re-use this - * NiceInputMessage in the next loop iteration. */ - n_valid_messages = 0; - } else { + } else if (parsed_buffer_length > 0) { *message->from = from; } + /* parsed_buffer_length == 0 means this is a TURN control message which + * needs ignoring. */ /* Split up the monolithic buffer again into the caller-provided buffers. */ if (parsed_buffer_length > 0 && allocated_buffer) { -- cgit v1.2.1