mirror of
https://github.com/tmux/tmux.git
synced 2026-05-30 14:16:18 +00:00
Sanitize pane titles and window and session names more consistently and
strictly, prevents C0 characters and other nonvisible characters causing problems. Reported (with a different fix) by Chris Monardo in GitHub issue 4999.
This commit is contained in:
@@ -102,7 +102,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
tmp = args_get(args, 's');
|
tmp = args_get(args, 's');
|
||||||
if (tmp != NULL) {
|
if (tmp != NULL) {
|
||||||
name = format_single(item, tmp, c, NULL, NULL, NULL);
|
name = format_single(item, tmp, c, NULL, NULL, NULL);
|
||||||
newname = session_check_name(name);
|
newname = clean_name(name, "#:.");
|
||||||
if (newname == NULL) {
|
if (newname == NULL) {
|
||||||
cmdq_error(item, "invalid session: %s", name);
|
cmdq_error(item, "invalid session: %s", name);
|
||||||
free(name);
|
free(name);
|
||||||
@@ -142,7 +142,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
else if (groupwith != NULL)
|
else if (groupwith != NULL)
|
||||||
prefix = xstrdup(groupwith->name);
|
prefix = xstrdup(groupwith->name);
|
||||||
else {
|
else {
|
||||||
prefix = session_check_name(group);
|
prefix = clean_name(group, "#:.");
|
||||||
if (prefix == NULL) {
|
if (prefix == NULL) {
|
||||||
cmdq_error(item, "invalid session group: %s",
|
cmdq_error(item, "invalid session group: %s",
|
||||||
group);
|
group);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
char *newname, *tmp;
|
char *newname, *tmp;
|
||||||
|
|
||||||
tmp = format_single_from_target(item, args_string(args, 0));
|
tmp = format_single_from_target(item, args_string(args, 0));
|
||||||
newname = session_check_name(tmp);
|
newname = clean_name(tmp, "#:.");
|
||||||
if (newname == NULL) {
|
if (newname == NULL) {
|
||||||
cmdq_error(item, "invalid session: %s", tmp);
|
cmdq_error(item, "invalid session: %s", tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|||||||
5
input.c
5
input.c
@@ -2626,13 +2626,10 @@ input_exit_osc(struct input_ctx *ictx)
|
|||||||
input_osc_4(ictx, p);
|
input_osc_4(ictx, p);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
if (utf8_isvalid(p)) {
|
if (screen_set_path(sctx->s, p) && wp != NULL) {
|
||||||
screen_set_path(sctx->s, p);
|
|
||||||
if (wp != NULL) {
|
|
||||||
server_redraw_window_borders(wp->window);
|
server_redraw_window_borders(wp->window);
|
||||||
server_status_window(wp->window);
|
server_status_window(wp->window);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
input_osc_8(ictx, p);
|
input_osc_8(ictx, p);
|
||||||
|
|||||||
4
names.c
4
names.c
@@ -166,7 +166,9 @@ parse_window_name(const char *in)
|
|||||||
|
|
||||||
if (*name == '/')
|
if (*name == '/')
|
||||||
name = basename(name);
|
name = basename(name);
|
||||||
name = xstrdup(name);
|
name = clean_name(name, "#");
|
||||||
free(copy);
|
free(copy);
|
||||||
|
if (name == NULL)
|
||||||
|
return (xstrdup(""));
|
||||||
return (name);
|
return (name);
|
||||||
}
|
}
|
||||||
|
|||||||
17
screen.c
17
screen.c
@@ -232,19 +232,28 @@ screen_set_cursor_colour(struct screen *s, int colour)
|
|||||||
int
|
int
|
||||||
screen_set_title(struct screen *s, const char *title)
|
screen_set_title(struct screen *s, const char *title)
|
||||||
{
|
{
|
||||||
if (!utf8_isvalid(title))
|
char *new_title;
|
||||||
|
|
||||||
|
new_title = clean_name(title, "#");
|
||||||
|
if (new_title == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
free(s->title);
|
free(s->title);
|
||||||
s->title = xstrdup(title);
|
s->title = new_title;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set screen path. */
|
/* Set screen path. */
|
||||||
void
|
int
|
||||||
screen_set_path(struct screen *s, const char *path)
|
screen_set_path(struct screen *s, const char *path)
|
||||||
{
|
{
|
||||||
|
char *new_path;
|
||||||
|
|
||||||
|
new_path = clean_name(path, "#");
|
||||||
|
if (new_path == NULL)
|
||||||
|
return (0);
|
||||||
free(s->path);
|
free(s->path);
|
||||||
utf8_stravis(&s->path, path, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL);
|
s->path = new_path;
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Push the current title onto the stack. */
|
/* Push the current title onto the stack. */
|
||||||
|
|||||||
18
session.c
18
session.c
@@ -231,24 +231,6 @@ session_destroy(struct session *s, int notify, const char *from)
|
|||||||
session_remove_ref(s, __func__);
|
session_remove_ref(s, __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sanitize session name. */
|
|
||||||
char *
|
|
||||||
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 == '.')
|
|
||||||
*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. */
|
/* Lock session if it has timed out. */
|
||||||
static void
|
static void
|
||||||
session_lock_timer(__unused int fd, __unused short events, void *arg)
|
session_lock_timer(__unused int fd, __unused short events, void *arg)
|
||||||
|
|||||||
8
spawn.c
8
spawn.c
@@ -84,6 +84,7 @@ spawn_window(struct spawn_context *sc, char **cause)
|
|||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
int idx = sc->idx;
|
int idx = sc->idx;
|
||||||
u_int sx, sy, xpixel, ypixel;
|
u_int sx, sy, xpixel, ypixel;
|
||||||
|
char *name;
|
||||||
|
|
||||||
spawn_log(__func__, sc);
|
spawn_log(__func__, sc);
|
||||||
|
|
||||||
@@ -182,8 +183,11 @@ spawn_window(struct spawn_context *sc, char **cause)
|
|||||||
if (~sc->flags & SPAWN_RESPAWN) {
|
if (~sc->flags & SPAWN_RESPAWN) {
|
||||||
free(w->name);
|
free(w->name);
|
||||||
if (sc->name != NULL) {
|
if (sc->name != NULL) {
|
||||||
w->name = format_single(item, sc->name, c, s, NULL,
|
name = format_single(item, sc->name, c, s, NULL, NULL);
|
||||||
NULL);
|
w->name = clean_name(name, "#");
|
||||||
|
free(name);
|
||||||
|
if (w->name == NULL)
|
||||||
|
w->name = xstrdup("");
|
||||||
options_set_number(w->options, "automatic-rename", 0);
|
options_set_number(w->options, "automatic-rename", 0);
|
||||||
} else
|
} else
|
||||||
w->name = default_window_name(w);
|
w->name = default_window_name(w);
|
||||||
|
|||||||
18
tmux.c
18
tmux.c
@@ -34,6 +34,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -285,6 +286,23 @@ get_timer(void)
|
|||||||
return ((ts.tv_sec * 1000ULL) + (ts.tv_nsec / 1000000ULL));
|
return ((ts.tv_sec * 1000ULL) + (ts.tv_nsec / 1000000ULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
clean_name(const char *name, const char* forbid)
|
||||||
|
{
|
||||||
|
char *copy, *cp, *new_name;
|
||||||
|
|
||||||
|
if (*name == '\0' || !utf8_isvalid(name))
|
||||||
|
return (NULL);
|
||||||
|
copy = xstrdup(name);
|
||||||
|
for (cp = copy; *cp != '\0'; cp++) {
|
||||||
|
if (strchr(forbid, *cp) != NULL)
|
||||||
|
*cp = '_';
|
||||||
|
}
|
||||||
|
utf8_stravis(&new_name, copy, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL);
|
||||||
|
free(copy);
|
||||||
|
return (new_name);
|
||||||
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
sig2name(int signo)
|
sig2name(int signo)
|
||||||
{
|
{
|
||||||
|
|||||||
4
tmux.h
4
tmux.h
@@ -2326,6 +2326,7 @@ int checkshell(const char *);
|
|||||||
void setblocking(int, int);
|
void setblocking(int, int);
|
||||||
char *shell_argv0(const char *, int);
|
char *shell_argv0(const char *, int);
|
||||||
uint64_t get_timer(void);
|
uint64_t get_timer(void);
|
||||||
|
char *clean_name(const char *, const char *);
|
||||||
const char *sig2name(int);
|
const char *sig2name(int);
|
||||||
const char *find_cwd(void);
|
const char *find_cwd(void);
|
||||||
const char *find_home(void);
|
const char *find_home(void);
|
||||||
@@ -3281,7 +3282,7 @@ void screen_set_default_cursor(struct screen *, struct options *);
|
|||||||
void screen_set_cursor_style(u_int, enum screen_cursor_style *, int *);
|
void screen_set_cursor_style(u_int, enum screen_cursor_style *, int *);
|
||||||
void screen_set_cursor_colour(struct screen *, int);
|
void screen_set_cursor_colour(struct screen *, int);
|
||||||
int screen_set_title(struct screen *, const char *);
|
int screen_set_title(struct screen *, const char *);
|
||||||
void screen_set_path(struct screen *, const char *);
|
int screen_set_path(struct screen *, const char *);
|
||||||
void screen_push_title(struct screen *);
|
void screen_push_title(struct screen *);
|
||||||
void screen_pop_title(struct screen *);
|
void screen_pop_title(struct screen *);
|
||||||
void screen_set_progress_bar(struct screen *, enum progress_bar_state, int);
|
void screen_set_progress_bar(struct screen *, enum progress_bar_state, int);
|
||||||
@@ -3587,7 +3588,6 @@ struct session *session_create(const char *, const char *, const char *,
|
|||||||
void session_destroy(struct session *, int, const char *);
|
void session_destroy(struct session *, int, const char *);
|
||||||
void session_add_ref(struct session *, const char *);
|
void session_add_ref(struct session *, const char *);
|
||||||
void session_remove_ref(struct session *, const char *);
|
void session_remove_ref(struct session *, const char *);
|
||||||
char *session_check_name(const char *);
|
|
||||||
void session_update_activity(struct session *, struct timeval *);
|
void session_update_activity(struct session *, struct timeval *);
|
||||||
struct session *session_next_session(struct session *, struct sort_criteria *);
|
struct session *session_next_session(struct session *, struct sort_criteria *);
|
||||||
struct session *session_previous_session(struct session *,
|
struct session *session_previous_session(struct session *,
|
||||||
|
|||||||
5
window.c
5
window.c
@@ -408,10 +408,15 @@ window_remove_ref(struct window *w, const char *from)
|
|||||||
void
|
void
|
||||||
window_set_name(struct window *w, const char *new_name)
|
window_set_name(struct window *w, const char *new_name)
|
||||||
{
|
{
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
name = clean_name(new_name, "#");
|
||||||
|
if (name != NULL) {
|
||||||
free(w->name);
|
free(w->name);
|
||||||
utf8_stravis(&w->name, new_name, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL);
|
utf8_stravis(&w->name, new_name, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL);
|
||||||
notify_window("window-renamed", w);
|
notify_window("window-renamed", w);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
window_resize(struct window *w, u_int sx, u_int sy, int xpixel, int ypixel)
|
window_resize(struct window *w, u_int sx, u_int sy, int xpixel, int ypixel)
|
||||||
|
|||||||
Reference in New Issue
Block a user