From e2b3eb91ddfb8690d45d4300f0f41cbb1137f22e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 10 Mar 2024 17:37:11 +0100 Subject: [PATCH] csi: params_to_rectangular_area(): ensure left/right is within bounds --- csi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/csi.c b/csi.c index 7a427f9e..d03ae40d 100644 --- a/csi.c +++ b/csi.c @@ -678,15 +678,16 @@ params_to_rectangular_area(const struct terminal *term, int first_idx, int *top, int *left, int *bottom, int *right) { int rel_top = vt_param_get(term, first_idx + 0, 1) - 1; - *left = vt_param_get(term, first_idx + 1, 1) - 1; + *left = min(vt_param_get(term, first_idx + 1, 1) - 1, term->cols - 1); int rel_bottom = vt_param_get(term, first_idx + 2, term->rows) - 1; - *right = vt_param_get(term, first_idx + 3, term->cols) - 1; + *right = min(vt_param_get(term, first_idx + 3, term->cols) - 1, term->cols - 1); if (rel_top > rel_bottom || *left > *right) return false; *top = term_row_rel_to_abs(term, rel_top); *bottom = term_row_rel_to_abs(term, rel_bottom); + return true; }