libmsc/db.c: warn user about SMS text truncation

In general, neither TP-User-Data nor decoded text should be
truncated. If the SMSC's database for some reason does contain
such weird messages, let's at least let the user know about it.

Change-Id: I75e852ebe44ba4784572cbffa029e13f0d3c430c
This commit is contained in:
Vadim Yanitskiy 2019-04-02 18:25:08 +07:00 committed by laforge
parent ea24bb50cc
commit 0d13e8358e
1 changed files with 10 additions and 0 deletions

View File

@ -229,6 +229,7 @@ static void parse_tp_ud_from_result(struct gsm_sms *sms, dbi_result result)
{
const unsigned char *user_data;
unsigned int user_data_len;
unsigned int text_len;
const char *text;
/* Retrieve TP-UDL (User-Data-Length) in octets (regardless of DCS) */
@ -247,6 +248,15 @@ static void parse_tp_ud_from_result(struct gsm_sms *sms, dbi_result result)
memcpy(sms->user_data, user_data, user_data_len);
}
/* Retrieve the text length (excluding '\0') */
text_len = dbi_result_get_field_length(result, "text");
if (text_len >= sizeof(sms->text)) {
LOGP(DDB, LOGL_ERROR,
"SMS text length %u is too big, truncating to %zu\n",
text_len, sizeof(sms->text) - 1);
/* OSMO_STRLCPY_ARRAY() does truncation for us */
}
/* Retrieve the text parsed from TP-UD (User-Data) */
text = dbi_result_get_string(result, "text");
if (text)