Module: kamailio
Branch: master
Commit: 4399fe3966f6774b18e02ea6e54a5ba132c7c4ab
URL:
https://github.com/kamailio/kamailio/commit/4399fe3966f6774b18e02ea6e54a5ba…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-12-21T13:56:28+01:00
sms: define buffer size for name field
- check size before copy and trucate large messages
---
Modified: src/modules/sms/libsms_getsms.c
Modified: src/modules/sms/sms_funcs.h
---
Diff:
https://github.com/kamailio/kamailio/commit/4399fe3966f6774b18e02ea6e54a5ba…
Patch:
https://github.com/kamailio/kamailio/commit/4399fe3966f6774b18e02ea6e54a5ba…
---
diff --git a/src/modules/sms/libsms_getsms.c b/src/modules/sms/libsms_getsms.c
index 0f6df6b7341..ea258ccf673 100644
--- a/src/modules/sms/libsms_getsms.c
+++ b/src/modules/sms/libsms_getsms.c
@@ -279,6 +279,7 @@ static int splitascii(struct modem *mdm, char *source, struct
incame_sms *sms)
char *end;
char tbuf[TIME_LEN + 1];
char dbuf[DATE_LEN + 1];
+ int l1 = 0;
/* the text is after the \r */
for(start = source; *start && *start != '\r'; start++)
@@ -313,7 +314,13 @@ static int splitascii(struct modem *mdm, char *source, struct
incame_sms *sms)
return 1;
}
*end = 0;
- strcpy(sms->name, start);
+ l1 = strlen(start);
+ if(l1 >= SMS_NAME_LEN) {
+ /* truncate */
+ l1 = SMS_NAME_LEN - 1;
+ }
+ memcpy(sms->name, start, l1);
+ sms->name[l1] = '\0';
}
/* Get the date */
start = end + 3;
diff --git a/src/modules/sms/sms_funcs.h b/src/modules/sms/sms_funcs.h
index e49427c91b7..4123b92c514 100644
--- a/src/modules/sms/sms_funcs.h
+++ b/src/modules/sms/sms_funcs.h
@@ -91,10 +91,11 @@ struct sms_msg
int ref;
};
+#define SMS_NAME_LEN 64
struct incame_sms
{
char sender[31];
- char name[64];
+ char name[SMS_NAME_LEN];
char date[DATE_LEN];
char time[TIME_LEN];
char ascii[500];