From b480b74192a7c00c4ea077286b921b96e42efabc Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Thu, 11 Apr 2019 06:58:44 +0200 Subject: add identifier sanitation for setting FSM instance ids We often compose FSM instance IDs from context information, for example placing an MSISDN string or IP:port information in the FSM instance id, using osmo_fsm_inst_update_id_f(). This fails if any characters are contained that don't pass osmo_identifier_valid(). Hence it is the task of the caller to make sure only characters allowed in an FSM id are applied. Provide API to trivially allow this by replacing illegal chars: - osmo_identifier_sanitize_buf(), with access to the same set of illegal characters defined in utils.c, - osmo_fsm_inst_update_id_f_sanitize() implicitly replaces non-identifier chars. This makes it easy to add strings like '192.168.0.1:2342' or '+4987654321' to an FSM instance id, without adding string mangling to each place that sets an id; e.g. replacing with '-' to yield '192-168-0-1:2342' or '-4987654321'. Change-Id: Ia40a6f3b2243c95fe428a080b938e11d8ab771a7 --- include/osmocom/core/fsm.h | 1 + include/osmocom/core/utils.h | 1 + 2 files changed, 2 insertions(+) (limited to 'include') diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h index c9e1e0cf..41d01a58 100644 --- a/include/osmocom/core/fsm.h +++ b/include/osmocom/core/fsm.h @@ -220,6 +220,7 @@ void osmo_fsm_inst_free(struct osmo_fsm_inst *fi); int osmo_fsm_inst_update_id(struct osmo_fsm_inst *fi, const char *id); int osmo_fsm_inst_update_id_f(struct osmo_fsm_inst *fi, const char *fmt, ...); +int osmo_fsm_inst_update_id_f_sanitize(struct osmo_fsm_inst *fi, char replace_with, const char *fmt, ...); const char *osmo_fsm_event_name(struct osmo_fsm *fsm, uint32_t event); const char *osmo_fsm_inst_name(struct osmo_fsm_inst *fi); diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h index 08735fdb..f27359cb 100644 --- a/include/osmocom/core/utils.h +++ b/include/osmocom/core/utils.h @@ -140,6 +140,7 @@ bool osmo_is_hexstr(const char *str, int min_digits, int max_digits, bool osmo_identifier_valid(const char *str); bool osmo_separated_identifiers_valid(const char *str, const char *sep_chars); +void osmo_identifier_sanitize_buf(char *str, const char *sep_chars, char replace_with); const char *osmo_escape_str(const char *str, int len); char *osmo_escape_str_buf2(char *buf, size_t bufsize, const char *str, int in_len); -- cgit v1.2.3