aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-gsm_a_dtap.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2009-12-27 21:33:28 +0000
committerGuy Harris <guy@alum.mit.edu>2009-12-27 21:33:28 +0000
commitfb3fccfc67da5f79ee5905892e5d347e46b7d2b7 (patch)
tree0160844a62f850e35ecaf310deaaedbef2156089 /epan/dissectors/packet-gsm_a_dtap.c
parente03e8553dd9d1a22fac26e1888e10a2b8c822987 (diff)
Some SMS characters require more than 2 bytes when encoded as UTF-8; the
maximum number of bytes required by UTF-8 for a single code point is 6 - that's probably overkill here, as I don't think any *SMS* characters require 6 bytes, but we'll go with an expansion factor of 6 anyway. This fixes bug 4358. svn path=/trunk/; revision=31365
Diffstat (limited to 'epan/dissectors/packet-gsm_a_dtap.c')
-rw-r--r--epan/dissectors/packet-gsm_a_dtap.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/epan/dissectors/packet-gsm_a_dtap.c b/epan/dissectors/packet-gsm_a_dtap.c
index cba219f304..61f0f67fa7 100644
--- a/epan/dissectors/packet-gsm_a_dtap.c
+++ b/epan/dissectors/packet-gsm_a_dtap.c
@@ -726,8 +726,22 @@ de_network_name(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint len, gcha
if (num_spare_bits == 7)
num_chars--;
a_bigbuf[num_chars] = '\0';
- /* There could be Greek chars, so better be safe */
- net_name = ep_alloc(2 * num_chars);
+ /*
+ * The documentation for g_unichar_to_utf8() says that
+ * the output buffer "must have at least 6 bytes of space".
+ * I think that maximum is for some Korean characters, so
+ * perhaps that's overkill here, but there are at least
+ * some SMS characters whose UTF-8 encoding takes 3
+ * bytes. We'll be safe and allocate 6 bytes.
+ *
+ * XXX - we could have a routine that takes a string of
+ * SMS characters and returns an ep_allocated UTF-8
+ * string. g_unichar_to_utf8(), if passed a null
+ * buffer pointer, just returns the number of bytes
+ * required, so we could get the right buffer size
+ * by making two passes over the SMS string.
+ */
+ net_name = ep_alloc(6 * num_chars);
gsm_sms_char_ascii_decode(net_name, a_bigbuf, num_chars);
proto_tree_add_text(tree, tvb , curr_offset, len - 1, "Text String: %s", net_name);
break;