mirror of git://git.sysmocom.de/ofono
sms: Fix alphanumeric TP-OA handling
TP-OA max length comparisons were incorrect because TP-OA's 7-bit coded octets transport eleven 8-bit chars. The current code assumed only 10 chars were possible. The patch - increases the array size to 23, (maximum of 22 bytes for UTF8 encoding + null terminator) - Updates the sanity check to account for the correct maximum - For encoding, checks the maximum length in UTF8 characters instead of bytes
This commit is contained in:
parent
604fa223f4
commit
2af3c733b7
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue