mirror of git://git.sysmocom.de/ofono
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.
This commit is contained in:
parent
7b3840c5ce
commit
bae8ebe907
|
@ -765,6 +765,20 @@ unsigned char *comprehension_tlv_builder_get_data(
|
||||||
return tlv + tag_size + len_size;
|
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,
|
static char *sim_network_name_parse(const unsigned char *buffer, int length,
|
||||||
gboolean *add_ci)
|
gboolean *add_ci)
|
||||||
{
|
{
|
||||||
|
|
|
@ -403,6 +403,7 @@ gboolean comprehension_tlv_builder_set_length(
|
||||||
unsigned int len);
|
unsigned int len);
|
||||||
unsigned char *comprehension_tlv_builder_get_data(
|
unsigned char *comprehension_tlv_builder_get_data(
|
||||||
struct comprehension_tlv_builder *builder);
|
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,
|
void ber_tlv_iter_init(struct ber_tlv_iter *iter, const unsigned char *pdu,
|
||||||
unsigned int len);
|
unsigned int len);
|
||||||
|
|
Loading…
Reference in New Issue