1 From 98ce2f265f986fb88c38d508286bb5e3716b9e74 Mon Sep 17 00:00:00 2001
2 From: Christian Persch <chpe@gnome.org>
3 Date: Sat, 19 May 2012 18:04:12 +0000
4 Subject: emulation: Limit repetitions
6 Don't allow malicious sequences to cause excessive repetitions.
8 https://bugzilla.gnome.org/show_bug.cgi?id=676090
10 diff --git a/src/vteseq.c b/src/vteseq.c
11 index 46def5b..7fb4707 100644
14 @@ -1397,7 +1397,7 @@ vte_sequence_handler_dc (VteTerminal *terminal, GValueArray *params)
16 vte_sequence_handler_DC (VteTerminal *terminal, GValueArray *params)
18 - vte_sequence_handler_multiple(terminal, params, vte_sequence_handler_dc);
19 + vte_sequence_handler_multiple_r(terminal, params, vte_sequence_handler_dc);
22 /* Delete a line at the current cursor position. */
23 @@ -1790,7 +1790,7 @@ vte_sequence_handler_reverse_index (VteTerminal *terminal, GValueArray *params)
25 vte_sequence_handler_RI (VteTerminal *terminal, GValueArray *params)
27 - vte_sequence_handler_multiple(terminal, params, vte_sequence_handler_nd);
28 + vte_sequence_handler_multiple_r(terminal, params, vte_sequence_handler_nd);
31 /* Save cursor (position). */
32 @@ -2782,8 +2782,7 @@ vte_sequence_handler_insert_lines (VteTerminal *terminal, GValueArray *params)
36 - long param, end, row;
38 + long param, end, row, i, limit;
39 screen = terminal->pvt->screen;
40 /* The default is one. */
42 @@ -2801,7 +2800,13 @@ vte_sequence_handler_insert_lines (VteTerminal *terminal, GValueArray *params)
44 end = screen->insert_delta + terminal->row_count - 1;
46 - /* Insert the new lines at the cursor. */
48 + /* Only allow to insert as many lines as there are between this row
49 + * and the end of the scrolling region. See bug #676090.
51 + limit = end - row + 1;
52 + param = MIN (param, limit);
54 for (i = 0; i < param; i++) {
55 /* Clear a line off the end of the region and add one to the
56 * top of the region. */
57 @@ -2822,8 +2827,7 @@ vte_sequence_handler_delete_lines (VteTerminal *terminal, GValueArray *params)
61 - long param, end, row;
63 + long param, end, row, i, limit;
65 screen = terminal->pvt->screen;
66 /* The default is one. */
67 @@ -2842,6 +2846,13 @@ vte_sequence_handler_delete_lines (VteTerminal *terminal, GValueArray *params)
69 end = screen->insert_delta + terminal->row_count - 1;
72 + /* Only allow to delete as many lines as there are between this row
73 + * and the end of the scrolling region. See bug #676090.
75 + limit = end - row + 1;
76 + param = MIN (param, limit);
78 /* Clear them from below the current cursor. */
79 for (i = 0; i < param; i++) {
80 /* Insert a line at the end of the region and remove one from