[MERGED] libosmocore[master]: fsm: Enforce FSM and FSM instance names are valid osmocom id...

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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Tue Oct 24 16:00:47 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: fsm: Enforce FSM and FSM instance names are valid osmocom identifiers
......................................................................


fsm: Enforce FSM and FSM instance names are valid osmocom identifiers

Let's enforce that the names of FSMs and their instances are valid
osmocom identifiers.  This is important as the FSMs are automatically
exported via those names on the CTRL inteface, and we have to make sure
CTRL syntax actually permits them.

Change-Id: I9ef59432f43a3cdb94e4cbb0c44ac3f9b2aac0f2
---
M src/fsm.c
1 file changed, 12 insertions(+), 1 deletion(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/fsm.c b/src/fsm.c
index d62fd79..3f8de9c 100644
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -146,6 +146,10 @@
  */
 int osmo_fsm_register(struct osmo_fsm *fsm)
 {
+	if (!osmo_identifier_valid(fsm->name)) {
+		LOGP(DLGLOBAL, LOGL_ERROR, "Attempting to register FSM with illegal identifier '%s'\n", fsm->name);
+		return -EINVAL;
+	}
 	if (osmo_fsm_find_by_name(fsm->name))
 		return -EEXIST;
 	llist_add_tail(&fsm->list, &osmo_g_fsms);
@@ -206,8 +210,15 @@
 	fi->priv = priv;
 	fi->log_level = log_level;
 	osmo_timer_setup(&fi->timer, fsm_tmr_cb, fi);
-	if (id)
+	if (id) {
+		if (!osmo_identifier_valid(id)) {
+			LOGP(DLGLOBAL, LOGL_ERROR, "Attempting to allocate FSM instance of type '%s'"
+			     " with illegal identifier '%s'\n", fsm->name, id);
+			talloc_free(fi);
+			return NULL;
+		}
 		fi->id = talloc_strdup(fi, id);
+	}
 
 	if (!fsm_log_addr) {
 		if (id)

-- 
To view, visit https://gerrit.osmocom.org/4129
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9ef59432f43a3cdb94e4cbb0c44ac3f9b2aac0f2
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list