This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Vadim Yanitskiy gerrit-no-reply at lists.osmocom.orgVadim Yanitskiy has uploaded this change for review. ( https://gerrit.osmocom.org/13490
Change subject: libmsc/db.c: properly get / set TP-UD length (octets vs septets)
......................................................................
libmsc/db.c: properly get / set TP-UD length (octets vs septets)
According to 3GPP TS 03.40, section 9.2.3.16, the TP-UDL field
indicates the length of TP-UD (User-Data, including TP-UDH)
either in septets, or in octets, depending on DSC in use.
When retrieving the TP-UD from the database, we get the length
in octets (bytes), regardless of the DCS value. Before this
patch, it was merely copied to struct 'gsm_sms', without
any conversion from octets to septets.
The same problem was in db_sms_store(), which could run into
a buffer overflow, using the amount of septets (e.g. 160) to
store some 8-bit or UCS-2 encoded data (up to 140 octets).
Change-Id: I84f973bc6561a9822b4b26975a781abd2b6e026a
---
M src/libmsc/db.c
1 file changed, 25 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/90/13490/1
diff --git a/src/libmsc/db.c b/src/libmsc/db.c
index 6cd8493..f48384e 100644
--- a/src/libmsc/db.c
+++ b/src/libmsc/db.c
@@ -38,6 +38,7 @@
#include <osmocom/msc/vlr.h>
#include <osmocom/gsm/protocol/gsm_23_003.h>
+#include <osmocom/gsm/gsm0411_utils.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/statistics.h>
#include <osmocom/core/rate_ctr.h>
@@ -227,6 +228,7 @@
static void parse_tp_ud_from_result(struct gsm_sms *sms, dbi_result result)
{
+ enum sms_alphabet dcs_alphabet;
const unsigned char *user_data;
unsigned int user_data_len;
unsigned int text_len;
@@ -240,12 +242,20 @@
user_data_len, sizeof(sms->user_data));
user_data_len = (uint8_t) sizeof(sms->user_data);
}
- sms->user_data_len = user_data_len;
/* Retrieve the TP-UD (User-Data) itself */
user_data = dbi_result_get_binary(result, "user_data");
memcpy(sms->user_data, user_data, user_data_len);
+ /* We may need to convert the length in octets to a value in septets,
+ * if 7-bit default alphabet is used (see 3GPP TS 03.40,
+ * section 9.2.3.16 for details). */
+ dcs_alphabet = gsm338_get_sms_alphabet(sms->data_coding_scheme);
+ if (dcs_alphabet == DCS_7BIT_DEFAULT)
+ sms->user_data_len = user_data_len * 8 / 7;
+ else
+ sms->user_data_len = user_data_len;
+
/* Retrieve the text length (excluding '\0') */
text_len = dbi_result_get_field_length(result, "text");
if (text_len >= sizeof(sms->text)) {
@@ -716,12 +726,24 @@
char *q_text, *q_daddr, *q_saddr;
unsigned char *q_udata;
time_t now, validity_timestamp;
+ enum sms_alphabet dcs_alphabet;
+ unsigned int user_data_len;
+
+ /* We may need to convert the length in septets to a value in octets,
+ * if 7-bit default alphabet is used (see 3GPP TS 03.40,
+ * section 9.2.3.16 for details). */
+ dcs_alphabet = gsm338_get_sms_alphabet(sms->data_coding_scheme);
+ if (dcs_alphabet == DCS_7BIT_DEFAULT) {
+ user_data_len = sms->user_data_len * 7 / 8;
+ if (sms->user_data_len * 7 % 8 != 0)
+ user_data_len++;
+ } else
+ user_data_len = sms->user_data_len;
dbi_conn_quote_string_copy(conn, (char *)sms->text, &q_text);
dbi_conn_quote_string_copy(conn, (char *)sms->dst.addr, &q_daddr);
dbi_conn_quote_string_copy(conn, (char *)sms->src.addr, &q_saddr);
- dbi_conn_quote_binary_copy(conn, sms->user_data, sms->user_data_len,
- &q_udata);
+ dbi_conn_quote_binary_copy(conn, sms->user_data, user_data_len, &q_udata);
now = time(NULL);
validity_timestamp = now + sms->validity_minutes * 60;
--
To view, visit https://gerrit.osmocom.org/13490
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I84f973bc6561a9822b4b26975a781abd2b6e026a
Gerrit-Change-Number: 13490
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190402/8f2d705d/attachment.htm>