Commit 7a39f60f authored by Olivier Crête's avatar Olivier Crête

stunmessage: Accept NULL terminated buffers for fast speed validation

parent 747364e2
......@@ -538,11 +538,11 @@ stun_message_append_error (StunMessage *msg, StunError code)
* they’re STUN packets. If they look like they might be, their buffers are
* compacted to allow a more thorough check. */
ssize_t stun_message_validate_buffer_length_fast (StunInputVector *buffers,
unsigned int n_buffers, size_t total_length, bool has_padding)
int n_buffers, size_t total_length, bool has_padding)
{
size_t mlen;
if (total_length < 1 || n_buffers < 1)
if (total_length < 1 || n_buffers == 0 || buffers[0].buffer == NULL)
{
stun_debug ("STUN error: No data!\n");
return STUN_MESSAGE_BUFFER_INVALID;
......@@ -569,7 +569,8 @@ ssize_t stun_message_validate_buffer_length_fast (StunInputVector *buffers,
unsigned int i;
/* Skip bytes. */
for (i = 0; i < n_buffers; i++) {
for (i = 0; (n_buffers >= 0 && i < (unsigned int) n_buffers) ||
(n_buffers < 0 && buffers[i].buffer != NULL); i++) {
if (buffers[i].size <= skip_remaining)
skip_remaining -= buffers[i].size;
else
......
......@@ -904,7 +904,8 @@ typedef struct {
* stun_message_validate_buffer_length_fast:
* @buffers: (array length=n_buffers) (in caller-allocated): array of contiguous
* #StunInputVectors containing already-received message data
* @n_buffers: number of entries in @buffers
* @n_buffers: number of entries in @buffers or if -1 , then buffers is
* terminated by a #StunInputVector with the buffer pointer being %NULL.
* @total_length: total number of valid bytes stored consecutively in @buffers
* @has_padding: %TRUE if attributes should be padded to 4-byte boundaries
*
......@@ -926,7 +927,7 @@ typedef struct {
* Since: 0.1.5
*/
ssize_t stun_message_validate_buffer_length_fast (StunInputVector *buffers,
unsigned int n_buffers, size_t total_length, bool has_padding);
int n_buffers, size_t total_length, bool has_padding);
/**
* stun_message_id:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment