diff options
author | Sergey Matyukevich <geomatsi@gmail.com> | 2021-01-16 22:21:05 +0300 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2021-01-19 10:03:05 -0600 |
commit | bae8ebe907a119cdcde156a3852b1b65e1fb35bb (patch) | |
tree | 6953f82fd60fd7de01a25f1fcc31dad0575485b4 | |
parent | 7b3840c5ce0018ae2e1a8c5b24d406884938588c (diff) | |
download | ofono-bae8ebe907a119cdcde156a3852b1b65e1fb35bb.tar.gz |
simutil: add validate_utf8_tlv
Add helper to validate if TLV value is a valid UTF8 string.
Note that both null-terminated and non null-terminated UTF8
strings are considered valid.
-rw-r--r-- | src/simutil.c | 14 | ||||
-rw-r--r-- | src/simutil.h | 1 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/simutil.c b/src/simutil.c index 4e0d3311..acb2aa2f 100644 --- a/src/simutil.c +++ b/src/simutil.c @@ -765,6 +765,20 @@ unsigned char *comprehension_tlv_builder_get_data( return tlv + tag_size + len_size; } +gboolean validate_utf8_tlv(const unsigned char *tlv) +{ + int len = tlv[1]; + + if (len == 0) + return FALSE; + + /* support both null-terminated and non null-terminated TLV value */ + if (tlv[len + 1] == '\0') + len -= 1; + + return g_utf8_validate_len((const char *)tlv + 2, len, NULL); +} + static char *sim_network_name_parse(const unsigned char *buffer, int length, gboolean *add_ci) { diff --git a/src/simutil.h b/src/simutil.h index 14a39957..33b775a7 100644 --- a/src/simutil.h +++ b/src/simutil.h @@ -403,6 +403,7 @@ gboolean comprehension_tlv_builder_set_length( unsigned int len); unsigned char *comprehension_tlv_builder_get_data( struct comprehension_tlv_builder *builder); +gboolean validate_utf8_tlv(const unsigned char *data); void ber_tlv_iter_init(struct ber_tlv_iter *iter, const unsigned char *pdu, unsigned int len); |