summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd-new-session.c12
-rw-r--r--cmd-rename-session.c4
-rw-r--r--cmd.c10
-rw-r--r--session.c7
-rw-r--r--tmux.h1
5 files changed, 29 insertions, 5 deletions
diff --git a/cmd-new-session.c b/cmd-new-session.c
index fc847bd2..5eaa5393 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -68,9 +68,15 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int sx, sy, i;
newname = args_get(args, 's');
- if (newname != NULL && session_find(newname) != NULL) {
- ctx->error(ctx, "duplicate session: %s", newname);
- return (-1);
+ if (newname != NULL) {
+ if (!session_check_name(newname)) {
+ ctx->error(ctx, "bad session name: %s", newname);
+ return (-1);
+ }
+ if (session_find(newname) != NULL) {
+ ctx->error(ctx, "duplicate session: %s", newname);
+ return (-1);
+ }
}
target = args_get(args, 't');
diff --git a/cmd-rename-session.c b/cmd-rename-session.c
index 018e537f..cbda700f 100644
--- a/cmd-rename-session.c
+++ b/cmd-rename-session.c
@@ -46,6 +46,10 @@ cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *newname;
newname = args->argv[0];
+ if (!session_check_name(newname)) {
+ ctx->error(ctx, "bad session name: %s", newname);
+ return (-1);
+ }
if (session_find(newname) != NULL) {
ctx->error(ctx, "duplicate session: %s", newname);
return (-1);
diff --git a/cmd.c b/cmd.c
index ac66f6e8..ee893a25 100644
--- a/cmd.c
+++ b/cmd.c
@@ -725,6 +725,12 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
if (arglen != 0 && tmparg[arglen - 1] == ':')
tmparg[arglen - 1] = '\0';
+ /* An empty session name is the current session. */
+ if (*tmparg == '\0') {
+ xfree (tmparg);
+ return (cmd_current_session(ctx, prefer_unattached));
+ }
+
/* Find the session, if any. */
s = cmd_lookup_session(tmparg, &ambiguous);
@@ -840,7 +846,7 @@ no_colon:
lookup_session:
if (ambiguous)
goto not_found;
- if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL)
+ if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL)
goto no_session;
if (sp != NULL)
@@ -981,7 +987,7 @@ no_colon:
lookup_session:
if (ambiguous)
goto not_found;
- if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL)
+ if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL)
goto no_session;
if (sp != NULL)
diff --git a/session.c b/session.c
index 9babd81c..e9bffed2 100644
--- a/session.c
+++ b/session.c
@@ -164,6 +164,13 @@ session_destroy(struct session *s)
RB_INSERT(sessions, &dead_sessions, s);
}
+/* Check a session name is valid: not empty and no colons. */
+int
+session_check_name(const char *name)
+{
+ return (*name != '\0' && strchr(name, ':') == NULL);
+}
+
/* Update session active time. */
void
session_update_activity(struct session *s)
diff --git a/tmux.h b/tmux.h
index a2af2a87..12f68085 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1978,6 +1978,7 @@ struct session *session_create(const char *, const char *, const char *,
struct environ *, struct termios *, int, u_int, u_int,
char **);
void session_destroy(struct session *);
+int session_check_name(const char *);
void session_update_activity(struct session *);
struct session *session_next_session(struct session *);
struct session *session_previous_session(struct session *);