From: nicm Date: Tue, 6 Jul 2021 08:18:38 +0000 (+0000) Subject: Forbid empty session names, GitHub issue 2758. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=998b9ee143f8bef1fe0d3c6eb1008691d020122b;p=openbsd Forbid empty session names, GitHub issue 2758. --- diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c index 4129872feac..134663cedde 100644 --- a/usr.bin/tmux/cmd-new-session.c +++ b/usr.bin/tmux/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-session.c,v 1.136 2021/06/10 07:24:45 nicm Exp $ */ +/* $OpenBSD: cmd-new-session.c,v 1.137 2021/07/06 08:18:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -102,6 +102,11 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) if (tmp != NULL) { name = format_single(item, tmp, c, NULL, NULL, NULL); newname = session_check_name(name); + if (newname == NULL) { + cmdq_error(item, "invalid session: %s", name); + free(name); + return (CMD_RETURN_ERROR); + } free(name); } if (args_has(args, 'A')) { @@ -134,8 +139,14 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) prefix = xstrdup(sg->name); else if (groupwith != NULL) prefix = xstrdup(groupwith->name); - else + else { prefix = session_check_name(group); + if (prefix == NULL) { + cmdq_error(item, "invalid session group: %s", + group); + goto fail; + } + } } /* Set -d if no client. */ diff --git a/usr.bin/tmux/cmd-rename-session.c b/usr.bin/tmux/cmd-rename-session.c index b58ee54095e..76932e841b5 100644 --- a/usr.bin/tmux/cmd-rename-session.c +++ b/usr.bin/tmux/cmd-rename-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-rename-session.c,v 1.32 2020/05/16 14:49:50 nicm Exp $ */ +/* $OpenBSD: cmd-rename-session.c,v 1.33 2021/07/06 08:18:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -53,6 +53,11 @@ cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item) tmp = format_single_from_target(item, args->argv[0]); newname = session_check_name(tmp); + if (newname == NULL) { + cmdq_error(item, "invalid session: %s", tmp); + free(tmp); + return (CMD_RETURN_ERROR); + } free(tmp); if (strcmp(newname, s->name) == 0) { free(newname); diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 3e1ec047d24..249d4293b28 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.87 2020/05/16 14:49:50 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.88 2021/07/06 08:18:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -237,6 +237,8 @@ session_check_name(const char *name) { char *copy, *cp, *new_name; + if (*name == '\0') + return (NULL); copy = xstrdup(name); for (cp = copy; *cp != '\0'; cp++) { if (*cp == ':' || *cp == '.')