Change in libosmocore[master]: osmo_fsm: Esnure all state and event names are valid identifiers

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

laforge gerrit-no-reply at lists.osmocom.org
Sun Dec 1 10:28:27 UTC 2019


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/16355 )


Change subject: osmo_fsm: Esnure all state and event names are valid identifiers
......................................................................

osmo_fsm: Esnure all state and event names are valid identifiers

we call osmo_identifier_valid() for the FSM name and FSM instance, but we
forgot to do so for all the state and event names.  This meant that they
could contain spaces and the like, which in turn might create problems
when exposing FSM state over CTRL.

This patch shouldn't be merged as-is right now.  We first have to
use it to determine which of our existing programs have related issues.

Change-Id: If98587eff3c48a66ed2e5cc1f01a12accab5a3e7
Closes: OS#4149
---
M src/fsm.c
1 file changed, 29 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/55/16355/1

diff --git a/src/fsm.c b/src/fsm.c
index 1e8909e..2f270cb 100644
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -286,10 +286,38 @@
  */
 int osmo_fsm_register(struct osmo_fsm *fsm)
 {
+	unsigned int i;
+	bool err = false;
+
+	/* first collect all errors regarding identifiers (not just the first one) */
 	if (!osmo_identifier_valid(fsm->name)) {
 		LOGP(DLGLOBAL, LOGL_ERROR, "Attempting to register FSM with illegal identifier '%s'\n", fsm->name);
-		return -EINVAL;
+		err = true;
 	}
+	for (i = 0; i < fsm->num_states; i++) {
+		const struct osmo_fsm_state *states = fsm->states;
+		if (!osmo_identifier_valid(states[i].name)) {
+			LOGP(DLGLOBAL, LOGL_ERROR, "Attempting to register FSM with illegal "
+			     "state name '%s'\n", states[i].name);
+			err = true;
+		}
+	}
+	if (fsm->event_names) {
+		const struct value_string *vs = fsm->event_names;
+		for (i = 0;; i++) {
+			if (vs[i].value == 0 && vs[i].str == NULL)
+				break;
+			if (!osmo_identifier_valid(vs[i].str)) {
+				LOGP(DLGLOBAL, LOGL_ERROR, "Attempting to register FSM with illegal"
+				     "event name '%s'\n", vs[i].str);
+				err = true;
+			}
+		}
+	}
+	/* then return -EINVAL in case any identifier error[s] were encountered */
+	if (err)
+		return -EINVAL;
+
 	if (osmo_fsm_find_by_name(fsm->name))
 		return -EEXIST;
 	if (fsm->event_names == NULL)

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16355
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If98587eff3c48a66ed2e5cc1f01a12accab5a3e7
Gerrit-Change-Number: 16355
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191201/53374856/attachment.htm>


More information about the gerrit-log mailing list