* [PATCH] sms: SMS-DELIVER TP-OA Alphanum decoding and encoding fix
@ 2015-02-13 15:50 Tommi Kenakkala
2015-02-13 16:01 ` Denis Kenzior
0 siblings, 1 reply; 2+ messages in thread
From: Tommi Kenakkala @ 2015-02-13 15:50 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2111 bytes --]
TP-OA max length comparisons were incorrect because TP-OA's 7-bit
coded octets transport eleven 8-bit chars which take 23 bytes in UTF-8.
Increase address array accordingly and don't compare byte length to
character limit, but to a proper limit.
---
src/smsutil.c | 12 +++++++++---
src/smsutil.h | 6 +++++-
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/smsutil.c b/src/smsutil.c
index be60ee9..213e50e 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -524,7 +524,8 @@ static gboolean encode_validity_period(const struct sms_validity_period *vp,
gboolean sms_encode_address_field(const struct sms_address *in, gboolean sc,
unsigned char *pdu, int *offset)
{
- size_t len = strlen(in->address);
+ const char *addr = (const char *)&in->address;
+ size_t len = strlen(addr);
unsigned char addr_len = 0;
unsigned char p[10];
@@ -546,7 +547,8 @@ gboolean sms_encode_address_field(const struct sms_address *in, gboolean sc,
unsigned char *gsm;
unsigned char *r;
- if (len > 11)
+ /* TP-OA's 10 octets transport 11 8-bit chars */
+ if (g_utf8_strlen(addr, strlen(addr)) > 11)
return FALSE;
gsm = convert_utf8_to_gsm(in->address, len, NULL, &written, 0);
@@ -675,7 +677,11 @@ gboolean sms_decode_address_field(const unsigned char *pdu, int len,
if (utf8 == NULL)
return FALSE;
- if (strlen(utf8) > 20) {
+ /*
+ * TP-OA's 10 octets transport 11 8-bit chars,
+ * 22 bytes+terminator in UTF-8.
+ */
+ if (strlen(utf8) > 22) {
g_free(utf8);
return FALSE;
}
diff --git a/src/smsutil.h b/src/smsutil.h
index b1001f8..d252810 100644
--- a/src/smsutil.h
+++ b/src/smsutil.h
@@ -220,7 +220,11 @@ enum cbs_geo_scope {
struct sms_address {
enum sms_number_type number_type;
enum sms_numbering_plan numbering_plan;
- char address[21]; /* Max 20 in semi-octet, 11 in alnum */
+ /*
+ * An alphanum TP-OA is 10 7-bit coded octets, which can carry
+ * 11 8-bit characters. 22 bytes + terminator in UTF-8.
+ */
+ char address[23];
};
struct sms_scts {
--
1.7.9.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] sms: SMS-DELIVER TP-OA Alphanum decoding and encoding fix
2015-02-13 15:50 [PATCH] sms: SMS-DELIVER TP-OA Alphanum decoding and encoding fix Tommi Kenakkala
@ 2015-02-13 16:01 ` Denis Kenzior
0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2015-02-13 16:01 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 527 bytes --]
Hi Tommi,
On 02/13/2015 09:50 AM, Tommi Kenakkala wrote:
> TP-OA max length comparisons were incorrect because TP-OA's 7-bit
> coded octets transport eleven 8-bit chars which take 23 bytes in UTF-8.
> Increase address array accordingly and don't compare byte length to
> character limit, but to a proper limit.
> ---
> src/smsutil.c | 12 +++++++++---
> src/smsutil.h | 6 +++++-
> 2 files changed, 14 insertions(+), 4 deletions(-)
>
Applied after tweaking the commit description.
Thanks,
-Denis
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-02-13 16:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-13 15:50 [PATCH] sms: SMS-DELIVER TP-OA Alphanum decoding and encoding fix Tommi Kenakkala
2015-02-13 16:01 ` Denis Kenzior
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.