From f9eb405921b1d427bd43d54b79e7cb98667a26af Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 25 Sep 2026 08:46:06 +0000 Subject: [PATCH 1/2] Do not overflow window indexes at INT_MAX in new-window -a and renumber-windows. GitHub issue 5637 from Alexandre Fiori. --- session.c | 16 ++++++++++++---- window.c | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/session.c b/session.c index 060e01fac..15d860b4a 100644 --- a/session.c +++ b/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.108 2026/09/21 12:43:36 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.109 2026/09/25 08:46:06 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -749,14 +749,21 @@ session_renumber_windows(struct session *s) struct winlink *wl, *wl1, *wl_new; struct winlinks old_wins; struct winlink_stack old_lastw; + u_int n; int new_idx, new_curw_idx, marked_idx = -1; + /* Start renumbering from the base-index if it's set. */ + new_idx = options_get_number(s->options, "base-index"); + + /* Leave the indexes alone if they do not all fit from there. */ + n = winlink_count(&s->windows); + if (n > (u_int)INT_MAX - (u_int)new_idx + 1) + return; + /* Save and replace old window list. */ memcpy(&old_wins, &s->windows, sizeof old_wins); RB_INIT(&s->windows); - /* Start renumbering from the base-index if it's set. */ - new_idx = options_get_number(s->options, "base-index"); new_curw_idx = 0; /* Go through the winlinks and assign new indexes. */ @@ -771,7 +778,8 @@ session_renumber_windows(struct session *s) if (wl == s->curw) new_curw_idx = wl_new->idx; - new_idx++; + if (RB_NEXT(winlinks, &old_wins, wl) != NULL) + new_idx++; } /* Fix the stack of last windows now. */ diff --git a/window.c b/window.c index 162358f0b..86cd0c6e3 100644 --- a/window.c +++ b/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.378 2026/09/24 11:19:39 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.379 2026/09/25 08:46:06 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -2425,7 +2425,7 @@ winlink_shuffle_up(struct session *s, struct winlink *wl, int before) { int idx, last; - if (wl == NULL) + if (wl == NULL || wl->idx == INT_MAX) return (-1); if (before) idx = wl->idx; From d87bd430b9c65c514c2ad329514d338888f5be43 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 25 Sep 2026 09:11:18 +0000 Subject: [PATCH 2/2] Fix some indentation. --- tmux.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tmux.c b/tmux.c index 18f4603bb..537c336b6 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.223 2026/08/17 14:47:41 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.224 2026/09/25 09:11:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -165,8 +165,8 @@ expand_paths(const char *s, char ***paths, u_int *n, int no_realpath) path = expanded; else { if (realpath(expanded, resolved) == NULL) { - log_debug("%s: realpath(\"%s\") failed: %s", __func__, - expanded, strerror(errno)); + log_debug("%s: realpath(\"%s\") failed: %s", + __func__, expanded, strerror(errno)); free(expanded); continue; }