aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/vt/vt_buf.c
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2026-05-26 16:19:47 +0000
committerEd Maste <emaste@FreeBSD.org>2026-06-07 17:12:28 +0000
commitb5a4f4bfbc95d5d5361da708728f7f4a6db2ee60 (patch)
tree87f5d4f044991be63f93de87c1efecb31c11f8c9 /sys/dev/vt/vt_buf.c
parent28833ade34e4eabbbbf985217e552ac589fb9329 (diff)
vt: Avoid integer overflow in CONS_HISTORY ioctl
Reviewed by: markj, vexeduxr Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D57250 (cherry picked from commit 0ae946e7223df5ef3f7980af1d774d7f593f6421) (cherry picked from commit deaaddf1d3c4283649945553ad7e3208c8424308)
Diffstat (limited to 'sys/dev/vt/vt_buf.c')
-rw-r--r--sys/dev/vt/vt_buf.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/sys/dev/vt/vt_buf.c b/sys/dev/vt/vt_buf.c
index ea27ea8a5ebf..0fd301bb662a 100644
--- a/sys/dev/vt/vt_buf.c
+++ b/sys/dev/vt/vt_buf.c
@@ -500,7 +500,6 @@ vtbuf_grow(struct vt_buf *vb, const term_pos_t *p, unsigned int history_size)
{
term_char_t *old, *new, **rows, **oldrows, **copyrows, *row, *oldrow;
unsigned int w, h, c, r, old_history_size;
- size_t bufsize, rowssize;
int history_full;
const teken_attr_t *a;
term_char_t ch;
@@ -511,10 +510,10 @@ vtbuf_grow(struct vt_buf *vb, const term_pos_t *p, unsigned int history_size)
history_size = MAX(history_size, p->tp_row);
/* Allocate new buffer. */
- bufsize = history_size * p->tp_col * sizeof(term_char_t);
- new = malloc(bufsize, M_VTBUF, M_WAITOK | M_ZERO);
- rowssize = history_size * sizeof(term_pos_t *);
- rows = malloc(rowssize, M_VTBUF, M_WAITOK | M_ZERO);
+ new = mallocarray(history_size, p->tp_col * sizeof(term_char_t),
+ M_VTBUF, M_WAITOK | M_ZERO);
+ rows = mallocarray(history_size, sizeof(term_pos_t *), M_VTBUF,
+ M_WAITOK | M_ZERO);
/* Toggle it. */
VTBUF_LOCK(vb);