diff options
author | Harald Welte <laforge@osmocom.org> | 2019-12-01 11:25:51 +0100 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2021-02-04 18:32:00 +0100 |
commit | ed2e1f1865ec1f085f10b4d82ee74108bf014b22 (patch) | |
tree | 21f7a726e58e603050f7acbde0d946e881216b59 /src | |
parent | f269f6d1d5dee177251cd2468b76a90ff677a4d5 (diff) |
osmo_fsm: Ensure all state and event names are valid identifierslaforge/context
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
Diffstat (limited to 'src')
-rw-r--r-- | src/fsm.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -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) |