All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Matyukevich <geomatsi@gmail.com>
To: ofono@ofono.org
Subject: [PATCH v3 3/3] unit: add validate_utf8_tlv tests
Date: Sat, 16 Jan 2021 22:21:07 +0300	[thread overview]
Message-ID: <20210116192107.18568-4-geomatsi@gmail.com> (raw)
In-Reply-To: <20210116192107.18568-1-geomatsi@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1829 bytes --]

---
 unit/test-simutil.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/unit/test-simutil.c b/unit/test-simutil.c
index 083bd4b2..6f8419b4 100644
--- a/unit/test-simutil.c
+++ b/unit/test-simutil.c
@@ -86,6 +86,27 @@ static void test_ber_tlv_iter(void)
 	test_buffer(valid_mms_params, sizeof(valid_mms_params));
 }
 
+static void test_validate_tlv(void)
+{
+	unsigned char impi_none[] = { 0x80, 0x0 };
+	unsigned char impi_empty[] = { 0x80, 0x1, '\0' };
+	unsigned char impi_term1[] = { 0x80, 0x3, 'F', 'O', 'O' };
+	unsigned char impi_term2[] = { 0x80, 0x4, 'F', 'O', 'O', '\0' };
+	unsigned char impi_term3[] = { 0x80, 0x3, 'F', 'O', 'O', 0xff, 0xff };
+	unsigned char impi_term4[] = { 0x80, 0x4, 'F', 'O', 'O', '\0', 0xff };
+	unsigned char impi_invalid1[] = { 0x80, 0x4, 'F', '\0', 'O', '\0' };
+	unsigned char impi_invalid2[] = { 0x80, 0x4, 0xff, 0xff, 0xff, 0xff };
+
+	g_assert(validate_utf8_tlv(impi_none) == FALSE);
+	g_assert(validate_utf8_tlv(impi_empty) == TRUE);
+	g_assert(validate_utf8_tlv(impi_term1) == TRUE);
+	g_assert(validate_utf8_tlv(impi_term2) == TRUE);
+	g_assert(validate_utf8_tlv(impi_term3) == TRUE);
+	g_assert(validate_utf8_tlv(impi_term4) == TRUE);
+	g_assert(validate_utf8_tlv(impi_invalid1) == FALSE);
+	g_assert(validate_utf8_tlv(impi_invalid2) == FALSE);
+}
+
 static void test_ber_tlv_builder_mms(void)
 {
 	struct ber_tlv_iter top_iter, nested_iter;
@@ -610,6 +631,7 @@ int main(int argc, char **argv)
 	g_test_init(&argc, &argv, NULL);
 
 	g_test_add_func("/testsimutil/ber tlv iter", test_ber_tlv_iter);
+	g_test_add_func("/testsimutil/ber tlv validate utf8", test_validate_tlv);
 	g_test_add_func("/testsimutil/ber tlv encode MMS",
 			test_ber_tlv_builder_mms);
 	g_test_add_func("/testsimutil/ber tlv encode EFpnn",

      parent reply	other threads:[~2021-01-16 19:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-16 19:21 [PATCH v3 0/3] sim: validate IMS private identity Sergey Matyukevich
2021-01-16 19:21 ` [PATCH v3 1/3] simutil: add validate_utf8_tlv Sergey Matyukevich
2021-01-19 16:04   ` Denis Kenzior
2021-01-16 19:21 ` [PATCH v3 2/3] sim: validate IMS private identity Sergey Matyukevich
2021-01-19 16:05   ` Denis Kenzior
2021-01-16 19:21 ` Sergey Matyukevich [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210116192107.18568-4-geomatsi@gmail.com \
    --to=geomatsi@gmail.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.