After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 652124 - malicious escape sequence causes gnome-terminal to exhaust memory
malicious escape sequence causes gnome-terminal to exhaust memory
Status: RESOLVED FIXED
Product: vte
Classification: Core
Component: general
0.24.x
Other Linux
: Normal critical
: ---
Assigned To: VTE Maintainers
VTE Maintainers
Depends on:
Blocks:
 
 
Reported: 2011-06-08 16:12 UTC by Josselin Mouette
Modified: 2011-06-14 21:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch the vte_sequence_handler_IC() function (640 bytes, patch)
2011-06-09 12:19 UTC, vladz
none Details | Review
patch (2.40 KB, patch)
2011-06-10 15:37 UTC, Christian Persch
none Details | Review

Description Josselin Mouette 2011-06-08 16:12:09 UTC
[ Original report: http://bugs.debian.org/629688 by “vladz” ]

When passing a huge value to the "insert-blank-characters" capability
(defined in caps.c), gnome-terminal crashes (and maybe other terminals
that depend on libvte9). 

  $ cat -n vte-0.24.3/src/caps.c:
  [...]
  418          {CSI "%d@", "insert-blank-characters", 0},

To reproduce the crash:
  printf "\033[100000000000000000@"

This causes the terminal to consume all available memory.
Comment 1 Behdad Esfahbod 2011-06-08 16:31:31 UTC
Anyone feel like looking into this?  Should be safe to limit any numbers read to something small, like 1024?
Comment 2 Behdad Esfahbod 2011-06-08 16:35:55 UTC
Just look for g_value_set_long() in table.c and trie.c.  Doesn't look hard.
Comment 3 Christian Persch 2011-06-08 18:43:40 UTC
/* Insert N characters. */
static void
vte_sequence_handler_IC (VteTerminal *terminal, GValueArray *params)
{
        vte_sequence_handler_multiple(terminal, params, vte_sequence_handler_ic);
}

Just introduce a vte_sequence_handler_multiple_limited variant that limits the number to the passed max.

What does xterm do here?
Comment 4 vladz 2011-06-09 12:19:57 UTC
Created attachment 189541 [details] [review]
Patch the vte_sequence_handler_IC() function
Comment 5 vladz 2011-06-09 12:21:38 UTC
Hi,

Xterm checks the parameter value inside the InsertChar() function, and sets
a default value if it's to big.  Where the default (limit variant) depends 
on the terminal size:

 xterm-261/util.c:

 [...]
 972 /*
 973  * Insert n blanks at the cursor's position, no wraparound
 974  */
 975 void
 976 InsertChar(XtermWidget xw, unsigned n)
 977 {
 [...]
 980     unsigned limit;
 {...]
 995     limit = (unsigned) (MaxCols(screen) - screen->cur_col);
 996
 997     if (n > limit)
 998         n = limit;

The patch I've attached above does the same thing.  Is this ok for you?
Comment 6 Behdad Esfahbod 2011-06-09 17:30:49 UTC
LGTM.  Have you tested this and works?
Comment 7 Christian Persch 2011-06-09 19:03:30 UTC
I don't think this is the right place for this check. In vte_sequence_handler_IC it's not assured that the params[0] is a GValue with a long.
Comment 8 Christian Persch 2011-06-10 15:37:02 UTC
Created attachment 189650 [details] [review]
patch
Comment 9 Christian Persch 2011-06-14 21:53:50 UTC
Fixed on vte-0-28 and master; 0.28.1 released.