summaryrefslogtreecommitdiffstats
path: root/src/fsm.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-10-03 17:44:03 +0800
committerHarald Welte <laforge@gnumonks.org>2017-10-24 16:00:45 +0000
commit8c4f5457aa185bc9d74b6962aaafdd263ea6af56 (patch)
tree69555f47fffedfc6ca231846948cae8bafb642e3 /src/fsm.c
parentfebe83c4243520ccc64544026d5f496ef945a9aa (diff)
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
Diffstat (limited to 'src/fsm.c')
-rw-r--r--src/fsm.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/fsm.c b/src/fsm.c
index d62fd792..3f8de9cd 100644
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -146,6 +146,10 @@ struct osmo_fsm_inst *osmo_fsm_inst_find_by_id(const struct osmo_fsm *fsm,
*/
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 @@ struct osmo_fsm_inst *osmo_fsm_inst_alloc(struct osmo_fsm *fsm, void *ctx, void
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)