From d39fdc49b47199d80c8ddaeaa19ca4c0af524afd Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 13 Feb 2024 08:03:50 +0000 Subject: [PATCH] Do not allow paste into panes which have exited, from Romain Francoise in GitHub issue 3830. --- usr.bin/tmux/cmd-paste-buffer.c | 7 ++++++- usr.bin/tmux/cmd-pipe-pane.c | 4 ++-- usr.bin/tmux/tmux.h | 3 ++- usr.bin/tmux/window.c | 8 +++++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/usr.bin/tmux/cmd-paste-buffer.c b/usr.bin/tmux/cmd-paste-buffer.c index e26727bdfee..6d2c3de39c0 100644 --- a/usr.bin/tmux/cmd-paste-buffer.c +++ b/usr.bin/tmux/cmd-paste-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-paste-buffer.c,v 1.41 2021/08/21 10:22:39 nicm Exp $ */ +/* $OpenBSD: cmd-paste-buffer.c,v 1.42 2024/02/13 08:03:50 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -55,6 +55,11 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item) size_t seplen, bufsize; int bracket = args_has(args, 'p'); + if (window_pane_exited(wp)) { + cmdq_error(item, "target pane has exited"); + return (CMD_RETURN_ERROR); + } + bufname = NULL; if (args_has(args, 'b')) bufname = args_get(args, 'b'); diff --git a/usr.bin/tmux/cmd-pipe-pane.c b/usr.bin/tmux/cmd-pipe-pane.c index 1ef733155f0..8a217436080 100644 --- a/usr.bin/tmux/cmd-pipe-pane.c +++ b/usr.bin/tmux/cmd-pipe-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-pipe-pane.c,v 1.60 2022/05/30 13:03:46 nicm Exp $ */ +/* $OpenBSD: cmd-pipe-pane.c,v 1.61 2024/02/13 08:03:50 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -69,7 +69,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item) sigset_t set, oldset; /* Do nothing if pane is dead. */ - if (wp->fd == -1 || (wp->flags & PANE_EXITED)) { + if (window_pane_exited(wp)) { cmdq_error(item, "target pane has exited"); return (CMD_RETURN_ERROR); } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 43bf574e530..105d18693fa 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1211 2023/09/15 15:49:05 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1212 2024/02/13 08:03:50 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -3047,6 +3047,7 @@ int window_pane_key(struct window_pane *, struct client *, struct session *, struct winlink *, key_code, struct mouse_event *); int window_pane_visible(struct window_pane *); +int window_pane_exited(struct window_pane *); u_int window_pane_search(struct window_pane *, const char *, int, int); const char *window_printable_flags(struct winlink *, int); diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index ef86f43b1c2..7454e5e23a0 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.287 2023/10/23 08:12:00 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.288 2024/02/13 08:03:50 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1204,6 +1204,12 @@ window_pane_visible(struct window_pane *wp) return (wp == wp->window->active); } +int +window_pane_exited(struct window_pane *wp) +{ + return (wp->fd == -1 || (wp->flags & PANE_EXITED)); +} + u_int window_pane_search(struct window_pane *wp, const char *term, int regex, int ignore) -- 2.20.1