diff options
author | Daniele Palmas <dnlplm@gmail.com> | 2022-12-14 13:49:17 +0100 |
---|---|---|
committer | Daniele Palmas <dnlplm@gmail.com> | 2022-12-22 22:16:33 +0100 |
commit | 23363567bcc5bccb169d3730ea128f631bb42570 (patch) | |
tree | 3c7a2a1562d0751601ac881a0d278507cf4eaf74 | |
parent | e7e3b5dd8b5a651065cd4e88103a7924ee515167 (diff) | |
download | libmbim-23363567bcc5bccb169d3730ea128f631bb42570.tar.gz |
libmbim-glib,tlv: allow 0-length strings for MBIM_TLV_TYPE_WCHAR_STR
Document Microsoft MBIM Extensions for 5G (rev 1.17) considers the possibility
of having wchar strings tlvs with datalength == 0 in the information buffer
(e.g. AccessString field in MBIM_CONNECT_INFO_EX3 data structure).
Modify mbim_tlv_string_get for dealing with these situations, returning an
empty string.
-rw-r--r-- | src/libmbim-glib/mbim-tlv.c | 3 | ||||
-rw-r--r-- | src/libmbim-glib/test/test-message-parser.c | 81 |
2 files changed, 84 insertions, 0 deletions
diff --git a/src/libmbim-glib/mbim-tlv.c b/src/libmbim-glib/mbim-tlv.c index 283abc2..e02d460 100644 --- a/src/libmbim-glib/mbim-tlv.c +++ b/src/libmbim-glib/mbim-tlv.c @@ -260,6 +260,9 @@ mbim_tlv_string_get (const MbimTlv *self, /* Duplicate array unconditionally to avoid alignment issues as we don't * know if the 16bit array is aligned properly or not in the TLV */ size = MBIM_TLV_GET_DATA_LENGTH (self); + /* If size == 0, an empty string is returned since 0-length strings are allowed */ + if (!size) + return g_strdup (""); tmp = (gunichar2 *) g_memdup ((gconstpointer) MBIM_TLV_FIELD_DATA (self), size); /* For BE systems, convert from LE to BE */ diff --git a/src/libmbim-glib/test/test-message-parser.c b/src/libmbim-glib/test/test-message-parser.c index 93a4d51..e13d94f 100644 --- a/src/libmbim-glib/test/test-message-parser.c +++ b/src/libmbim-glib/test/test-message-parser.c @@ -2612,6 +2612,86 @@ test_ms_basic_connect_v3_connect_0_unnamed_tlvs (void) } static void +test_ms_basic_connect_v3_connect_0_unnamed_tlvs_empty_access_string (void) +{ + g_autoptr(GError) error = NULL; + g_autoptr(MbimMessage) response = NULL; + gboolean result; + GList *unnamed_ies = NULL; + guint32 session_id; + MbimActivationState activation_state; + MbimVoiceCallState voice_call_state; + MbimContextIpType ip_type; + MbimAccessMediaType media_type = MBIM_ACCESS_MEDIA_TYPE_UNKNOWN; + g_autofree gchar *access_string = NULL; + const MbimUuid *context_type; + guint32 nw_error; + + const guint8 buffer [] = { + /* header */ + 0x03, 0x00, 0x00, 0x80, /* type */ + 0x60, 0x00, 0x00, 0x00, /* length */ + 0x04, 0x00, 0x00, 0x00, /* transaction id */ + /* fragment header */ + 0x01, 0x00, 0x00, 0x00, /* total */ + 0x00, 0x00, 0x00, 0x00, /* current */ + /* command_done_message */ + 0xA2, 0x89, 0xCC, 0x33, /* service id */ + 0xBC, 0xBB, 0x8B, 0x4F, + 0xB6, 0xB0, 0x13, 0x3E, + 0xC2, 0xAA, 0xE6, 0xDF, + 0x0C, 0x00, 0x00, 0x00, /* command id */ + 0x00, 0x00, 0x00, 0x00, /* status code */ + 0x30, 0x00, 0x00, 0x00, /* buffer_length */ + /* information buffer */ + 0x01, 0x00, 0x00, 0x00, /* session id */ + 0x01, 0x00, 0x00, 0x00, /* activation state */ + 0x00, 0x00, 0x00, 0x00, /* voice call state */ + 0x01, 0x00, 0x00, 0x00, /* ip type */ + 0x7E, 0x5E, 0x2A, 0x7E, /* context type */ + 0x4E, 0x6F, 0x72, 0x72, + 0x73, 0x6B, 0x65, 0x6E, + 0x7E, 0x5E, 0x2A, 0x7E, + 0x00, 0x00, 0x00, 0x00, /* nw error */ + 0x01, 0x00, 0x00, 0x00, /* media type */ + 0x0A, 0x00, 0x00, 0x00, /* access string empty */ + 0x00, 0x00, 0x00, 0x00, + /* no unnamed TLVs */ + }; + + response = mbim_message_new (buffer, sizeof (buffer)); + g_assert (mbim_message_validate (response, &error)); + g_assert_no_error (error); + + test_message_printable (response, 3, 0); + + result = (mbim_message_ms_basic_connect_v3_connect_response_parse ( + response, + &session_id, + &activation_state, + &voice_call_state, + &ip_type, + &context_type, + &nw_error, + &media_type, + &access_string, + &unnamed_ies, + &error)); + + g_assert_no_error (error); + g_assert (result); + + g_assert_cmpuint (session_id, ==, 1); + g_assert_cmpuint (activation_state, ==, MBIM_ACTIVATION_STATE_ACTIVATED); + g_assert_cmpuint (voice_call_state, ==, MBIM_VOICE_CALL_STATE_NONE); + g_assert_cmpuint (ip_type, ==, MBIM_CONTEXT_IP_TYPE_IPV4); + g_assert_cmpuint (mbim_uuid_to_context_type (context_type), ==, MBIM_CONTEXT_TYPE_INTERNET); + g_assert_cmpuint (media_type, ==, MBIM_ACCESS_MEDIA_TYPE_3GPP); + g_assert_cmpstr (access_string, ==, ""); + g_assert_cmpuint (g_list_length (unnamed_ies), ==, 0); +} + +static void test_ms_basic_connect_v3_connect_1_unnamed_tlv (void) { g_autoptr(GError) error = NULL; @@ -3346,6 +3426,7 @@ int main (int argc, char **argv) g_test_add_func (PREFIX "/basic-connect-extensions/registration-parameters/1-unnamed-tlv", test_ms_basic_connect_extensions_registration_parameters_1_unnamed_tlv); g_test_add_func (PREFIX "/basic-connect-extensions/registration-parameters/3-unnamed-tlvs", test_ms_basic_connect_extensions_registration_parameters_3_unnamed_tlvs); g_test_add_func (PREFIX "/basic-connect-v3/connect/0-unnamed-tlvs", test_ms_basic_connect_v3_connect_0_unnamed_tlvs); + g_test_add_func (PREFIX "/basic-connect-v3/connect/0-unnamed-tlvs-empty-access-string", test_ms_basic_connect_v3_connect_0_unnamed_tlvs_empty_access_string); g_test_add_func (PREFIX "/basic-connect-v3/connect/1-unnamed-tlv", test_ms_basic_connect_v3_connect_1_unnamed_tlv); g_test_add_func (PREFIX "/basic-connect-v3/connect/3-unnamed-tlvs", test_ms_basic_connect_v3_connect_3_unnamed_tlvs); g_test_add_func (PREFIX "/basic-connect-extensions/device-caps-v3", test_ms_basic_connect_extensions_device_caps_v3); |