From ed2e1f1865ec1f085f10b4d82ee74108bf014b22 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 1 Dec 2019 11:25:51 +0100 Subject: osmo_fsm: Ensure 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 --- src/fsm.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/fsm.c b/src/fsm.c index f1dbb412..f8ddd487 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -286,10 +286,38 @@ struct osmo_fsm_inst *osmo_fsm_inst_find_by_id(const struct osmo_fsm *fsm, */ 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) -- cgit v1.2.3