summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/tmux/cmd-new-session.c14
-rw-r--r--usr.bin/tmux/cmd-rename-session.c6
-rw-r--r--usr.bin/tmux/cmd.c12
-rw-r--r--usr.bin/tmux/session.c9
-rw-r--r--usr.bin/tmux/tmux.h3
5 files changed, 34 insertions, 10 deletions
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index ac28108307e..9f1b20e196d 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.37 2011/04/05 19:37:01 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.38 2011/04/06 21:51:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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/usr.bin/tmux/cmd-rename-session.c b/usr.bin/tmux/cmd-rename-session.c
index afa3b349f0b..2743609be82 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.9 2011/04/05 19:37:01 nicm Exp $ */
+/* $OpenBSD: cmd-rename-session.c,v 1.10 2011/04/06 21:51:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index e07ba43ee46..4080b27182b 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.52 2011/04/05 19:37:01 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.53 2011/04/06 21:51:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index 04bd6996881..e05ba7b4d13 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.30 2011/01/25 22:31:50 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.31 2011/04/06 21:51:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 6de1857befa..5f0f6f02bed 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.278 2011/04/05 19:37:01 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.279 2011/04/06 21:51:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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 *);