summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-10-29 10:54:48 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-10-30 15:10:06 +0100
commitdb4e96c1d675bbdb2eebb938f49adfb2f9a0eacf (patch)
tree6b40c67f47121584f23c13fc6672685ea8f3fad9
parent97e2c720c592c30d70fc9a1a88cb6bf804cbbee2 (diff)
libqmi-glib,test: new test for messages with invalid TLVs
-rw-r--r--libqmi-glib/qmi-message.c6
-rw-r--r--libqmi-glib/test/test-message.c30
2 files changed, 34 insertions, 2 deletions
diff --git a/libqmi-glib/qmi-message.c b/libqmi-glib/qmi-message.c
index 4dd88cf..084f434 100644
--- a/libqmi-glib/qmi-message.c
+++ b/libqmi-glib/qmi-message.c
@@ -691,8 +691,12 @@ qmi_message_new_from_raw (GByteArray *raw,
/* We need to have read the length reported by the QMUX header (plus the
* initial 1-byte marker) */
message_len = GUINT16_FROM_LE (((struct full_message *)raw->data)->qmux.length);
- if (raw->len < (message_len + 1))
+ if (raw->len < (message_len + 1)) {
+ g_printerr ("\ngot '%u' bytes, need '%u' bytes\n",
+ (guint)raw->len,
+ (guint)(message_len + 1));
return NULL;
+ }
/* Ok, so we should have all the data available already */
self = g_byte_array_sized_new (message_len + 1);
diff --git a/libqmi-glib/test/test-message.c b/libqmi-glib/test/test-message.c
index f1da8ee..1a305f0 100644
--- a/libqmi-glib/test/test-message.c
+++ b/libqmi-glib/test/test-message.c
@@ -37,7 +37,8 @@ test_message_parse_common (const guint8 *buffer,
message = qmi_message_new_from_raw (array, &error);
if (!message) {
if (error) {
- g_debug ("Error creating message from raw data: '%s'", error->message);
+ if (n_messages < n_expected_messages)
+ g_printerr ("error creating message from raw data: '%s'\n", error->message);
g_error_free (error);
}
break;
@@ -110,6 +111,32 @@ test_message_parse_complete_and_complete (void)
test_message_parse_common (buffer, sizeof (buffer), 2);
}
+static void
+test_message_parse_wrong_tlv (void)
+{
+ const guint8 buffer[] = {
+ 0x01, 0x4F, 0x00, 0x80, 0x03, 0x03, 0x02, 0x01, 0x00, 0x24, 0x00, 0x43,
+ 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x04, 0x00, 0x02,
+ 0x03, 0x00, 0x00, 0x1D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x02,
+ 0x00, 0x00, 0x00, 0x15, 0x03, 0x00, 0x01, 0x05, 0x01, 0x12, 0x0E, 0x00,
+ 0x36, 0x01, 0x04, 0x01, 0x09, 0x20, 0x54, 0x2D, 0x4D, 0x6F, 0x62, 0x69,
+ 0x6C, 0x65, 0x11, 0x02, 0x00, 0x01, 0x05, 0x10, 0x01, 0x00, 0x01, 0x01,
+ 0x06, 0x00, 0x01, 0x01, 0x01, 0x02, 0x01, 0x05
+ };
+
+#if GLIB_CHECK_VERSION (2,34,0)
+ g_test_expect_message ("Qmi",
+ G_LOG_LEVEL_WARNING,
+ "Cannot read the '*' TLV: expected '*' bytes, but only got '*' bytes");
+#endif
+
+ test_message_parse_common (buffer, sizeof (buffer), 1);
+
+#if GLIB_CHECK_VERSION (2,34,0)
+ g_test_assert_expected_messages ();
+#endif
+}
+
int main (int argc, char **argv)
{
g_type_init ();
@@ -119,6 +146,7 @@ int main (int argc, char **argv)
g_test_add_func ("/libqmi-glib/message/parse/complete", test_message_parse_complete);
g_test_add_func ("/libqmi-glib/message/parse/complete-and-short", test_message_parse_complete_and_short);
g_test_add_func ("/libqmi-glib/message/parse/complete-and-complete", test_message_parse_complete_and_complete);
+ g_test_add_func ("/libqmi-glib/message/parse/wrong-tlv", test_message_parse_wrong_tlv);
return g_test_run ();
}