Commit 7111a6fe authored by Dafydd Harries's avatar Dafydd Harries

support STUN attributes that aren't a multiple of 4 bytes long

darcs-hash:20070126090121-c9803-c74ae3b4fc28b79b2668d4ba1aafa330d947d162.gz
parent 1c04b65d
......@@ -41,10 +41,6 @@ _stun_attribute_unpack (StunAttribute *attr, guint length, const gchar *s)
/* must start with 16 bit type, 16 bit length */
return FALSE;
if (length % 4 != 0)
/* attributes must be aligned to 32 bits */
return FALSE;
type = ntohs (*(guint16 *) s);
switch (type)
......@@ -182,6 +178,8 @@ stun_message_unpack (guint length, gchar *s)
for (offset = 20; offset < length; offset += attr_length)
{
attr_length = 4 + ntohs (*(guint16 *)(s + offset + 2));
/* pad to multiple of 4 bytes */
attr_length += 4 - (attr_length % 4);
n_attributes++;
}
......@@ -197,6 +195,8 @@ stun_message_unpack (guint length, gchar *s)
attr_length = 4 + ntohs (*(guint16 *)(s + offset + 2));
attr = msg->attributes[i] = stun_attribute_unpack (attr_length,
s + offset);
/* pad to multiple of 4 bytes */
attr_length += 4 - (attr_length % 4);
}
return msg;
......
......@@ -116,10 +116,6 @@ START_TEST (test_attribute_unpack_wrong_length)
attr = stun_attribute_unpack (0, NULL);
fail_unless (NULL == attr);
// attributes must aligned to 32 bits
attr = stun_attribute_unpack (33, NULL);
fail_unless (NULL == attr);
attr = stun_attribute_unpack (8,
"\x00\x01" // type = MAPPED-ADDRESS
"\x00\x04" // length = 4 (invalid!)
......
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