[PATCH] * Fix null ptr dereference and sms memleak in case the recipient of an sms sent via vty is not attached. Store the sms in the database in this case for later delivery.

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/OpenBSC@lists.osmocom.org/.

Nico Golde openbsc at ngolde.de
Tue Jun 29 18:13:06 UTC 2010


The problem is that sms_from_text returns NULL in case the
subscriber is not attached which a) leaks memory of the 
previously allocated sms and b) runs into a null ptr 
dereference in _send_sms_str().

There may be a better solution than this but this is the 
easiest way of noticing and taking action I could find 
without changing return values of sms_from_text.

---
 openbsc/src/vty_interface_layer3.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/openbsc/src/vty_interface_layer3.c b/openbsc/src/vty_interface_layer3.c
index d80f7c9..0a65eec 100644
--- a/openbsc/src/vty_interface_layer3.c
+++ b/openbsc/src/vty_interface_layer3.c
@@ -166,11 +166,6 @@ struct gsm_sms *sms_from_text(struct gsm_subscriber *receiver, const char *text)
 	if (!sms)
 		return NULL;
 
-	if (!receiver->lac) {
-		/* subscriber currently not attached, store in database? */
-		return NULL;
-	}
-
 	sms->receiver = subscr_get(receiver);
 	strncpy(sms->text, text, sizeof(sms->text)-1);
 
@@ -195,7 +190,16 @@ static int _send_sms_str(struct gsm_subscriber *receiver, char *str,
 
 	sms = sms_from_text(receiver, str);
 	sms->protocol_id = tp_pid;
-	gsm411_send_sms_subscr(receiver, sms);
+
+	if(!receiver->lac){
+		/* subscriber currently not attached, store in database */
+		if (db_sms_store(sms) != 0) {
+			LOGP(DSMS, LOGL_ERROR, "Failed to store SMS in Database\n");
+			return CMD_WARNING;
+		}
+	} else {
+		gsm411_send_sms_subscr(receiver, sms);
+	}
 
 	return CMD_SUCCESS;
 }
-- 
1.7.1





More information about the OpenBSC mailing list