Commit e40e4899 authored by Dafydd Harries's avatar Dafydd Harries

stun_message_unpack (): return NULL rather than aborting when message is invalid

darcs-hash:20070219122615-c9803-444a79d35558eb0b1183a0645732197bba56bb4f.gz
parent 89292b9f
...@@ -231,7 +231,8 @@ stun_message_unpack (guint length, const gchar *s) ...@@ -231,7 +231,8 @@ stun_message_unpack (guint length, const gchar *s)
/* message header is 20 bytes */ /* message header is 20 bytes */
g_assert (length >= 20); if (length < 20)
return NULL;
/* count the number of attributes */ /* count the number of attributes */
......
...@@ -4,7 +4,16 @@ ...@@ -4,7 +4,16 @@
int int
main (void) main (void)
{ {
StunMessage *msg = stun_message_unpack (32, StunMessage *msg;
/* invalid message */
msg = stun_message_unpack (5, "hello");
g_assert (msg == NULL);
/* valid message */
msg = stun_message_unpack (32,
"\x00\x01" // type "\x00\x01" // type
"\x00\x0c" // length "\x00\x0c" // length
"\x00\x01\x02\x03" // transaction ID "\x00\x01\x02\x03" // transaction 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