summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/session.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2020-05-16 14:49:50 +0000
committernicm <nicm@openbsd.org>2020-05-16 14:49:50 +0000
commitc27246d42322a7b3a9fc642a23d44fe4d5eb433e (patch)
tree74c74c54f593223b149f5289c1b36cf5ef0f6354 /usr.bin/tmux/session.c
parentInstead of having a default set of terminals in terminal-overrides that (diff)
downloadwireguard-openbsd-c27246d42322a7b3a9fc642a23d44fe4d5eb433e.tar.xz
wireguard-openbsd-c27246d42322a7b3a9fc642a23d44fe4d5eb433e.zip
Instead of forbidding invalid session names, sanitize them like window
names.
Diffstat (limited to 'usr.bin/tmux/session.c')
-rw-r--r--usr.bin/tmux/session.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index a379f217fe6..3e1ec047d24 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.86 2019/12/26 11:04:58 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.87 2020/05/16 14:49:50 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -23,6 +23,7 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+#include <vis.h>
#include <time.h>
#include "tmux.h"
@@ -123,7 +124,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);
@@ -142,7 +142,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);
@@ -232,11 +231,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. */
@@ -556,6 +564,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);
}
}