csi: params_to_rectangular_area(): ensure left/right is within bounds

This commit is contained in:
Daniel Eklöf 2024-03-10 17:37:11 +01:00
parent 4ea4e5da4e
commit e2b3eb91dd
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

5
csi.c
View file

@ -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;
}