diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2020-04-24 16:40:10 +0100 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2020-04-24 16:40:10 +0100 |
commit | 9b571daceec3ba038c669e90e20c3c0c2c755c57 (patch) | |
tree | 4c558a2b3b7cf54028192afcaacf782581bcc9eb /session.c | |
parent | 527f66ed23a88a59fb3d8c1972336f55612059bf (diff) | |
download | rtmux-9b571daceec3ba038c669e90e20c3c0c2c755c57.tar.gz rtmux-9b571daceec3ba038c669e90e20c3c0c2c755c57.tar.bz2 rtmux-9b571daceec3ba038c669e90e20c3c0c2c755c57.zip |
Instead of forbidding invalid session names, sanitize them.
Diffstat (limited to 'session.c')
-rw-r--r-- | session.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -122,7 +122,6 @@ session_create(const char *prefix, const char *name, const char *cwd, s->cwd = xstrdup(cwd); - s->curw = NULL; TAILQ_INIT(&s->lastw); RB_INIT(&s->windows); @@ -141,7 +140,6 @@ session_create(const char *prefix, const char *name, const char *cwd, s->name = xstrdup(name); s->id = next_session_id++; } else { - s->name = NULL; do { s->id = next_session_id++; free(s->name); @@ -231,11 +229,20 @@ session_destroy(struct session *s, int notify, const char *from) session_remove_ref(s, __func__); } -/* Check a session name is valid: not empty and no colons or periods. */ -int +/* Sanitize session name. */ +char * session_check_name(const char *name) { - return (*name != '\0' && name[strcspn(name, ":.")] == '\0'); + char *copy, *cp, *new_name; + + copy = xstrdup(name); + for (cp = copy; *cp != '\0'; cp++) { + if (*cp == ':' || *cp == '.') + *cp = '_'; + } + utf8_stravis(&new_name, copy, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL); + free(copy); + return (new_name); } /* Lock session if it has timed out. */ @@ -555,6 +562,7 @@ session_group_remove(struct session *s) TAILQ_REMOVE(&sg->sessions, s, gentry); if (TAILQ_EMPTY(&sg->sessions)) { RB_REMOVE(session_groups, &session_groups, sg); + free((void *)sg->name); free(sg); } } |