From 83f6ee00cf01aa72b220d3504a221bd3fe615b9c Mon Sep 17 00:00:00 2001 From: zhouwenpei Date: Thu, 30 Mar 2023 09:23:59 +0000 Subject: [PATCH] fix memleak in screen_set_path (cherry picked from commit a3de536e921cbedbd536fb71ee5342b471625860) --- ...freeing-screen-from-Sergey-Nizovtsev.patch | 31 ++++ ...--and-put-the-result-in-a-new-format.patch | 140 ++++++++++++++++++ tmux.spec | 7 +- 3 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 Do-not-leak-path-when-freeing-screen-from-Sergey-Nizovtsev.patch create mode 100644 Handle-OSC-7--and-put-the-result-in-a-new-format.patch diff --git a/Do-not-leak-path-when-freeing-screen-from-Sergey-Nizovtsev.patch b/Do-not-leak-path-when-freeing-screen-from-Sergey-Nizovtsev.patch new file mode 100644 index 0000000..e64c646 --- /dev/null +++ b/Do-not-leak-path-when-freeing-screen-from-Sergey-Nizovtsev.patch @@ -0,0 +1,31 @@ +From 02197f20d0809a5c248a32ef0ca3a45c7e3566bd Mon Sep 17 00:00:00 2001 +From: nicm +Date: Fri, 30 Oct 2020 11:33:41 +0000 +Subject: [PATCH] Do not leak path when freeing screen, from Sergey Nizovtsev. + +--- + screen.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/screen.c b/screen.c +index 405932e..3dd185d 100644 +--- a/screen.c ++++ b/screen.c +@@ -77,6 +77,7 @@ screen_init(struct screen *s, u_int sx, u_int sy, u_int hlimit) + s->grid = grid_create(sx, sy, hlimit); + s->title = xstrdup(""); + s->titles = NULL; ++ s->path = NULL; + + s->cstyle = 0; + s->ccolour = xstrdup(""); +@@ -112,6 +113,7 @@ screen_free(struct screen *s) + { + free(s->sel); + free(s->tabs); ++ free(s->path); + free(s->title); + free(s->ccolour); + +-- +2.27.0 diff --git a/Handle-OSC-7--and-put-the-result-in-a-new-format.patch b/Handle-OSC-7--and-put-the-result-in-a-new-format.patch new file mode 100644 index 0000000..acb0a02 --- /dev/null +++ b/Handle-OSC-7--and-put-the-result-in-a-new-format.patch @@ -0,0 +1,140 @@ +From f3dc38dcae472286c7d7c2708e4dbfe70a6c2d57 Mon Sep 17 00:00:00 2001 +From: nicm +Date: Fri, 15 Nov 2019 11:16:53 +0000 +Subject: [PATCH] Handle OSC 7 (a VTE extension) and put the result in a new + format (pane_path). + +--- + format.c | 1 + + input.c | 7 +++++++ + screen.c | 8 ++++++++ + tmux.1 | 9 +++++---- + tmux.h | 2 ++ + 5 files changed, 23 insertions(+), 4 deletions(-) + +diff --git a/format.c b/format.c +index 485a3bc..49eed46 100644 +--- a/format.c ++++ b/format.c +@@ -2026,6 +2026,7 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) + format_add(ft, "pane_width", "%u", wp->sx); + format_add(ft, "pane_height", "%u", wp->sy); + format_add(ft, "pane_title", "%s", wp->base.title); ++ format_add(ft, "pane_path", "%s", wp->base.path); + format_add(ft, "pane_id", "%%%u", wp->id); + format_add(ft, "pane_active", "%d", wp == w->active); + format_add(ft, "pane_input_off", "%d", !!(wp->flags & PANE_INPUTOFF)); +diff --git a/input.c b/input.c +index f959799..b4a534b 100644 +--- a/input.c ++++ b/input.c +@@ -132,6 +132,7 @@ static void input_set_state(struct window_pane *, + static void input_reset_cell(struct input_ctx *); + + static void input_osc_4(struct input_ctx *, const char *); ++static void input_osc_7(struct input_ctx *, const char *); + static void input_osc_10(struct input_ctx *, const char *); + static void input_osc_11(struct input_ctx *, const char *); + static void input_osc_52(struct input_ctx *, const char *); +@@ -2183,6 +2184,12 @@ input_exit_osc(struct input_ctx *ictx) + case 4: + input_osc_4(ictx, p); + break; ++ case 7: ++ if (utf8_isvalid(p)) { ++ screen_set_path(sctx->s, p); ++ server_status_window(ictx->wp->window); ++ } ++ break; + case 10: + input_osc_10(ictx, p); + break; +diff --git a/screen.c b/screen.c +index 9b67e7e..405932e 100644 +--- a/screen.c ++++ b/screen.c +@@ -158,6 +158,14 @@ screen_set_title(struct screen *s, const char *title) + utf8_stravis(&s->title, title, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL); + } + ++/* Set screen path. */ ++void ++screen_set_path(struct screen *s, const char *path) ++{ ++ free(s->path); ++ utf8_stravis(&s->path, path, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL); ++} ++ + /* Push the current title onto the stack. */ + void + screen_push_title(struct screen *s) +diff --git a/tmux.1 b/tmux.1 +index 3ba7077..a5f1f8f 100644 +--- a/tmux.1 ++++ b/tmux.1 +@@ -3895,7 +3895,7 @@ The following variables are available, where appropriate: + .It Li "pane_current_path" Ta "" Ta "Current path if available" + .It Li "pane_dead" Ta "" Ta "1 if pane is dead" + .It Li "pane_dead_status" Ta "" Ta "Exit status of process in dead pane" +-.It Li "pane_format" Ta "" Ta "1 if format is for a pane (not assuming the current)" ++.It Li "pane_format" Ta "" Ta "1 if format is for a pane" + .It Li "pane_height" Ta "" Ta "Height of pane" + .It Li "pane_id" Ta "#D" Ta "Unique pane ID" + .It Li "pane_in_mode" Ta "" Ta "If pane is in a mode" +@@ -3903,6 +3903,7 @@ The following variables are available, where appropriate: + .It Li "pane_index" Ta "#P" Ta "Index of pane" + .It Li "pane_left" Ta "" Ta "Left of pane" + .It Li "pane_mode" Ta "" Ta "Name of pane mode, if any." ++.It Li "pane_path" Ta "#T" Ta "Path of pane (can be set by application)" + .It Li "pane_pid" Ta "" Ta "PID of first process in pane" + .It Li "pane_pipe" Ta "" Ta "1 if pane is being piped" + .It Li "pane_right" Ta "" Ta "Right of pane" +@@ -3910,7 +3911,7 @@ The following variables are available, where appropriate: + .It Li "pane_start_command" Ta "" Ta "Command pane started with" + .It Li "pane_synchronized" Ta "" Ta "If pane is synchronized" + .It Li "pane_tabs" Ta "" Ta "Pane tab positions" +-.It Li "pane_title" Ta "#T" Ta "Title of pane" ++.It Li "pane_title" Ta "#T" Ta "Title of pane (can be set by application)" + .It Li "pane_top" Ta "" Ta "Top of pane" + .It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane" + .It Li "pane_width" Ta "" Ta "Width of pane" +@@ -3924,7 +3925,7 @@ The following variables are available, where appropriate: + .It Li "session_attached" Ta "" Ta "Number of clients session is attached to" + .It Li "session_activity" Ta "" Ta "Time of session last activity" + .It Li "session_created" Ta "" Ta "Time session created" +-.It Li "session_format" Ta "" Ta "1 if format is for a session (not assuming the current)" ++.It Li "session_format" Ta "" Ta "1 if format is for a session" + .It Li "session_last_attached" Ta "" Ta "Time session last attached" + .It Li "session_group" Ta "" Ta "Name of session group" + .It Li "session_group_size" Ta "" Ta "Size of session group" +@@ -3945,7 +3946,7 @@ The following variables are available, where appropriate: + .It Li "window_bigger" Ta "" Ta "1 if window is larger than client" + .It Li "window_end_flag" Ta "" Ta "1 if window has the highest index" + .It Li "window_flags" Ta "#F" Ta "Window flags" +-.It Li "window_format" Ta "" Ta "1 if format is for a window (not assuming the current)" ++.It Li "window_format" Ta "" Ta "1 if format is for a window" + .It Li "window_height" Ta "" Ta "Height of window" + .It Li "window_id" Ta "" Ta "Unique window ID" + .It Li "window_index" Ta "#I" Ta "Index of window" +diff --git a/tmux.h b/tmux.h +index d7f3819..0998e29 100644 +--- a/tmux.h ++++ b/tmux.h +@@ -699,6 +699,7 @@ struct screen_sel; + struct screen_titles; + struct screen { + char *title; ++ char *path; + struct screen_titles *titles; + + struct grid *grid; /* grid data */ +@@ -2194,6 +2195,7 @@ void screen_reset_tabs(struct screen *); + void screen_set_cursor_style(struct screen *, u_int); + void screen_set_cursor_colour(struct screen *, const char *); + void screen_set_title(struct screen *, const char *); ++void screen_set_path(struct screen *, const char *); + void screen_push_title(struct screen *); + void screen_pop_title(struct screen *); + void screen_resize(struct screen *, u_int, u_int, int); +-- +2.27.0 diff --git a/tmux.spec b/tmux.spec index 58d64cc..4e15a2c 100644 --- a/tmux.spec +++ b/tmux.spec @@ -2,7 +2,7 @@ Name: tmux Version: 2.9a -Release: 2 +Release: 3 Summary: A terminal multiplexer License: ISC and BSD @@ -11,6 +11,8 @@ Source0: https://github.com/%{name}/%{name}/releases/download/%{version}/ Source1: bash_completion_tmux.sh Patch1: CVE-2020-27347.patch +Patch6000: Handle-OSC-7--and-put-the-result-in-a-new-format.patch +Patch6001: Do-not-leak-path-when-freeing-screen-from-Sergey-Nizovtsev.patch BuildRequires: gcc libevent-devel ncurses-devel libutempter-devel @@ -65,6 +67,9 @@ fi %{_mandir}/man1/%{name}.1.gz %changelog +* Thu Mar 30 2023 zhouwenpei - 2.9a-3 +- fix memleak in screen_set_path + * Sat Nov 28 2020 wangye - 2.9a-2 - fix CVE -- Gitee