Module: kamailio
Branch: master
Commit: 904a718d15e4a83d752b6d2f0fa692fb10cda4b4
URL:
https://github.com/kamailio/kamailio/commit/904a718d15e4a83d752b6d2f0fa692f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-12-22T15:10:51+01:00
sms: define size and check lenght for sender and ascii fields
---
Modified: src/modules/sms/libsms_getsms.c
Modified: src/modules/sms/sms_funcs.h
---
Diff:
https://github.com/kamailio/kamailio/commit/904a718d15e4a83d752b6d2f0fa692f…
Patch:
https://github.com/kamailio/kamailio/commit/904a718d15e4a83d752b6d2f0fa692f…
---
diff --git a/src/modules/sms/libsms_getsms.c b/src/modules/sms/libsms_getsms.c
index ea258ccf673..4181560490e 100644
--- a/src/modules/sms/libsms_getsms.c
+++ b/src/modules/sms/libsms_getsms.c
@@ -287,7 +287,13 @@ static int splitascii(struct modem *mdm, char *source, struct
incame_sms *sms)
if(!*start)
return 1;
start++;
- strcpy(sms->ascii, start);
+ l1 = strlen(start);
+ if(l1 >= SMS_ASCII_LEN) {
+ /* truncate */
+ l1 = SMS_ASCII_LEN - 1;
+ }
+ memcpy(sms->ascii, start, l1);
+ sms->ascii[l1] = '\0';
/* get the senders MSISDN */
start = strstr(source, "\",\"");
if(start == 0) {
@@ -301,7 +307,14 @@ static int splitascii(struct modem *mdm, char *source, struct
incame_sms *sms)
return 1;
}
*end = 0;
- strcpy(sms->sender, start);
+ l1 = strlen(start);
+ if(l1 >= SMS_SENDER_LEN) {
+ /* truncate */
+ l1 = SMS_SENDER_LEN - 1;
+ }
+ memcpy(sms->sender, start, l1);
+ sms->sender[l1] = '\0';
+
/* Siemens M20 inserts the senders name between MSISDN and date */
start = end + 3;
// Workaround for Thomas Stoeckel //
diff --git a/src/modules/sms/sms_funcs.h b/src/modules/sms/sms_funcs.h
index 4123b92c514..84c35c2f3a4 100644
--- a/src/modules/sms/sms_funcs.h
+++ b/src/modules/sms/sms_funcs.h
@@ -92,14 +92,18 @@ struct sms_msg
};
#define SMS_NAME_LEN 64
+#define SMS_SENDER_LEN 32
+#define SMS_ASCII_LEN 500
+#define SMS_SMSC_LEN 32
+
struct incame_sms
{
- char sender[31];
+ char sender[SMS_SENDER_LEN];
char name[SMS_NAME_LEN];
char date[DATE_LEN];
char time[TIME_LEN];
- char ascii[500];
- char smsc[31];
+ char ascii[SMS_ASCII_LEN];
+ char smsc[SMS_SMSC_LEN];
int userdatalength;
int is_statusreport;
int sms_id;