aboutsummaryrefslogtreecommitdiff
path: root/cmd-new-session.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2020-04-24 16:40:10 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2020-04-24 16:40:10 +0100
commit9b571daceec3ba038c669e90e20c3c0c2c755c57 (patch)
tree4c558a2b3b7cf54028192afcaacf782581bcc9eb /cmd-new-session.c
parent527f66ed23a88a59fb3d8c1972336f55612059bf (diff)
downloadrtmux-9b571daceec3ba038c669e90e20c3c0c2c755c57.tar.gz
rtmux-9b571daceec3ba038c669e90e20c3c0c2c755c57.tar.bz2
rtmux-9b571daceec3ba038c669e90e20c3c0c2c755c57.zip
Instead of forbidding invalid session names, sanitize them.
Diffstat (limited to 'cmd-new-session.c')
-rw-r--r--cmd-new-session.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 353f7bed..f08155c0 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -70,13 +70,14 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
struct cmd_find_state *current = cmdq_get_current(item);
struct cmd_find_state *target = cmdq_get_target(item);
struct client *c = cmdq_get_client(item);
- struct session *s, *as, *groupwith;
+ struct session *s, *as, *groupwith = NULL;
struct environ *env;
struct options *oo;
struct termios tio, *tiop;
- struct session_group *sg;
- const char *errstr, *template, *group, *prefix, *tmp;
+ struct session_group *sg = NULL;
+ const char *errstr, *template, *group, *tmp;
char *cause, *cwd = NULL, *cp, *newname = NULL;
+ char *name, *prefix = NULL;
int detached, already_attached, is_control = 0;
u_int sx, sy, dsx, dsy;
struct spawn_context sc;
@@ -98,11 +99,9 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
tmp = args_get(args, 's');
if (tmp != NULL) {
- newname = format_single(item, tmp, c, NULL, NULL, NULL);
- if (!session_check_name(newname)) {
- cmdq_error(item, "bad session name: %s", newname);
- goto fail;
- }
+ name = format_single(item, tmp, c, NULL, NULL, NULL);
+ newname = session_check_name(name);
+ free(name);
}
if (args_has(args, 'A')) {
if (newname != NULL)
@@ -126,24 +125,16 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
group = args_get(args, 't');
if (group != NULL) {
groupwith = target->s;
- if (groupwith == NULL) {
- if (!session_check_name(group)) {
- cmdq_error(item, "bad group name: %s", group);
- goto fail;
- }
+ if (groupwith == NULL)
sg = session_group_find(group);
- } else
+ else
sg = session_group_contains(groupwith);
if (sg != NULL)
- prefix = sg->name;
+ prefix = xstrdup(sg->name);
else if (groupwith != NULL)
- prefix = groupwith->name;
+ prefix = xstrdup(groupwith->name);
else
- prefix = group;
- } else {
- groupwith = NULL;
- sg = NULL;
- prefix = NULL;
+ prefix = session_check_name(group);
}
/* Set -d if no client. */
@@ -353,10 +344,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
free(cwd);
free(newname);
+ free(prefix);
return (CMD_RETURN_NORMAL);
fail:
free(cwd);
free(newname);
+ free(prefix);
return (CMD_RETURN_ERROR);
}