[ModemManager] [PATCH 4/4] Calculate user-data bit padding correctly.



Fourth and final in a series.

This fixes an off-by-one (septet) error in the calculation of the
amount of data to skip in the presence of a user data header, and adds
the test case from the wild that triggered it.

    - Nathan
From 2c7a7c5752d42b7c2a1bb75865889eb49aaeeb30 Mon Sep 17 00:00:00 2001
From: Nathan Williams <njw chromium org>
Date: Wed, 29 Jun 2011 21:33:37 -0400
Subject: [PATCH 4/4] Calculate user-data bit padding correctly.

Deal correctly with the bit padding for the user data header for the
case where the correct amount of padding is 0. Prevents skipping the
first character of the message.

Add a unit test for this.

Change-Id: Ifa7bf7ea173b7da7aecffb9f4285ef2d8467cb03
---
 src/mm-sms-utils.c   |    6 +++++-
 src/tests/test-sms.c |   29 +++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/src/mm-sms-utils.c b/src/mm-sms-utils.c
index 6b01cf5..3f56a64 100644
--- a/src/mm-sms-utils.c
+++ b/src/mm-sms-utils.c
@@ -349,7 +349,11 @@ sms_parse_pdu (const char *hexpdu, GError **error)
         udhl = pdu[user_data_offset] + 1;
         user_data_offset += udhl;
         if (user_data_encoding == MM_SMS_ENCODING_GSM7) {
-            bit_offset = 7 - (udhl * 8) % 7;
+            /*
+             * Find the number of bits we need to add to the length of the
+             * user data to get a multiple of 7 (the padding).
+             */
+            bit_offset = (7 - udhl % 7) % 7;
             user_data_len -= (udhl * 8 + bit_offset) / 7;
         } else
             user_data_len -= udhl;
diff --git a/src/tests/test-sms.c b/src/tests/test-sms.c
index dfbb195..bd18c0b 100644
--- a/src/tests/test-sms.c
+++ b/src/tests/test-sms.c
@@ -339,6 +339,34 @@ test_pdu_insufficient_data (void *f, gpointer d)
   g_free (hexpdu);
 }
 
+
+static void
+test_pdu_udhi (void *f, gpointer d)
+{
+  /* Welcome message from KPN NL */
+  static const char *hexpdu =
+"07911356131313F64004850120390011609232239180A006080400100201D7327BFD6EB340E232"
+"1BF46E83EA7790F59D1E97DBE1341B442F83C465763D3DA797E56537C81D0ECB41AB59CC1693C1"
+"6031D96C064241E5656838AF03A96230982A269BCD462917C8FA4E8FCBED709A0D7ABBE9F6B0FB"
+"5C7683D27350984D4FABC9A0B33C4C4FCF5D20EBFB2D079DCB62793DBD06D9C36E50FB2D4E97D9"
+"A0B49B5E96BBCB";
+  GHashTable *sms;
+  GError *error;
+
+  sms = sms_parse_pdu (hexpdu, &error);
+  g_assert (sms);
+
+  TEST_ENTRY_EQ (sms, "smsc", "+31653131316");
+  TEST_ENTRY_EQ (sms, "number", "1002");
+  TEST_ENTRY_EQ (sms, "timestamp", "110629233219+02");
+  TEST_ENTRY_EQ (sms, "text",
+                 "Welkom, bel om uw Voicemail te beluisteren naar +31612001233"
+                 " (PrePay: *100*1233#). Voicemail ontvangen is altijd gratis."
+                 " Voor gebruik van mobiel interne");
+
+  g_hash_table_unref (sms);
+}
+
 #if 0
 static void
 test_pduX (void *f, gpointer d)
@@ -393,6 +421,7 @@ int main (int argc, char **argv)
     g_test_suite_add (suite, TESTCASE (test_pdu_dcsf1, NULL));
     g_test_suite_add (suite, TESTCASE (test_pdu_dcsf_8bit, NULL));
     g_test_suite_add (suite, TESTCASE (test_pdu_insufficient_data, NULL));
+    g_test_suite_add (suite, TESTCASE (test_pdu_udhi, NULL));
 
     result = g_test_run ();
 
-- 
1.7.3.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]