aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Greer <mgreer@animalcreek.com>2017-02-16 21:35:20 +0000
committerSamuel Ortiz <sameo@linux.intel.com>2017-11-10 00:23:49 +0100
commitc7e3d72b90e91f32af5a5e6e3d143e3cf2dc8be9 (patch)
tree454c68e1c8760e6bcf6580dbd41ecc664230d874
parent23f864ef891a26420b1b855ac768d7d1fc99085d (diff)
downloadneard-c7e3d72b90e91f32af5a5e6e3d143e3cf2dc8be9.tar.gz
ndef: Validate text data in WKT Text records
Ensure that the text encodings in WKT Text records are valid. Signed-off-by: Mark Greer <mgreer@animalcreek.com>
-rw-r--r--src/ndef.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/ndef.c b/src/ndef.c
index cad6227..3d88156 100644
--- a/src/ndef.c
+++ b/src/ndef.c
@@ -1149,8 +1149,10 @@ static struct near_ndef_text_payload *
parse_text_payload(uint8_t *payload, uint32_t length)
{
struct near_ndef_text_payload *text_payload = NULL;
- uint8_t status, lang_length;
+ uint8_t status, lang_length, len;
+ char *g_str, *txt;
uint32_t offset;
+ gboolean valid;
DBG("");
@@ -1185,9 +1187,26 @@ parse_text_payload(uint8_t *payload, uint32_t length)
offset += lang_length;
- if ((length - lang_length - 1) > 0) {
- text_payload->data = g_strndup((char *)(payload + offset),
- length - lang_length - 1);
+ len = length - lang_length - 1;
+
+ if (len > 0) {
+ txt = (char *)(payload + offset);
+
+ if (status)
+ g_str = g_utf16_to_utf8((gunichar2 *)txt, len, NULL,
+ NULL, NULL);
+ else
+ g_str = txt;
+
+ valid = g_utf8_validate(g_str, len, NULL);
+
+ if (status)
+ g_free(g_str);
+
+ if (!valid)
+ goto fail;
+
+ text_payload->data = g_strndup(txt, len);
} else {
text_payload->data = NULL;
}