From 7b31d6a05357953c035e2ab05ec117ef748f7798 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Thu, 15 Oct 2026 12:40:44 +0300 Subject: Reject a scrollback above TERM_SCROLLBACK_MAX term_new() silently cut a scrollback above 1000000 lines to 1000000. The limit now has a name in term.h, and term_new() returns NULL above it, as it does for the other invalid options. Co-Authored-By: Claude Opus 5.5 --- src/screen.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/screen.c') diff --git a/src/screen.c b/src/screen.c index b99948d..ab6989a 100644 --- a/src/screen.c +++ b/src/screen.c @@ -808,12 +808,10 @@ void term_screen_set_alternate(struct term *t, bool enabled) } } -/* The caller has checked that requested is not negative. */ +/* The caller has checked that requested is in [0, TERM_SCROLLBACK_MAX]. */ static int scrollback_lines(int requested) { - if (requested == 0) - return TERM_SCROLLBACK_DEFAULT; - return requested > 1000000 ? 1000000 : requested; + return requested == 0 ? TERM_SCROLLBACK_DEFAULT : requested; } static atomic_int tables_state; @@ -862,7 +860,8 @@ struct term *term_new(const struct term_options *opt) return NULL; if (opt->size.x < 0 || opt->size.y < 0 || opt->size.x > TERM_MAX_COLS) return NULL; - if (opt->scrollback < 0 || (unsigned)opt->cursor_style > TERM_CURSOR_BAR) + if (opt->scrollback < 0 || opt->scrollback > TERM_SCROLLBACK_MAX || + (unsigned)opt->cursor_style > TERM_CURSOR_BAR) return NULL; const char *name = opt->name && *opt->name ? opt->name : "term"; if (!name_valid(name)) -- cgit v1.2.3