diff options
author | Adam Borowski <kilobyte@angband.pl> | 2014-02-18 19:38:04 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-02-28 19:25:47 -0500 |
commit | 63f3a16db915096d7a80a96748adba00feb07a32 (patch) | |
tree | 131d7ba0b5809848aa71728b107b57d3e54fd28d /drivers/tty | |
parent | b290af68de57196e7cb34805f41cd3416ed1a791 (diff) |
vt: detect and ignore OSC codes.
These can be used to send commands consisting of an arbitrary string to the
terminal, most often used to set a terminal's window title or to redefine
the colour palette. Our console doesn't use OSC, unlike everything else,
which can lead to junk being displayed if a process sends such a code
unconditionally.
The rules for termination follow established practice rather than Ecma-48.
Ecma-48 requires the string to use only byte values 0x08..0x0D and
0x20..0x7E, terminated with either ESC \ or 0x9C. This would disallow using
8-bit characters, which are reasonable for example in window titles.
A widespread idiom is to terminate with 0x07. The behaviour for other
control characters differs between terminal emulators, I followed libvte and
xterm:
* 0x07 and ESC anything terminate
* nothing else terminates, all 8-bit values including 0x9C are considered a
part of the string
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r-- | drivers/tty/vt/vt.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index b7bde54db138..3ad0b61e35b4 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c | |||
@@ -1592,7 +1592,7 @@ static void restore_cur(struct vc_data *vc) | |||
1592 | 1592 | ||
1593 | enum { ESnormal, ESesc, ESsquare, ESgetpars, ESfunckey, | 1593 | enum { ESnormal, ESesc, ESsquare, ESgetpars, ESfunckey, |
1594 | EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd, | 1594 | EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd, |
1595 | ESpalette }; | 1595 | ESpalette, ESosc }; |
1596 | 1596 | ||
1597 | /* console_lock is held (except via vc_init()) */ | 1597 | /* console_lock is held (except via vc_init()) */ |
1598 | static void reset_terminal(struct vc_data *vc, int do_clear) | 1598 | static void reset_terminal(struct vc_data *vc, int do_clear) |
@@ -1652,11 +1652,15 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) | |||
1652 | * Control characters can be used in the _middle_ | 1652 | * Control characters can be used in the _middle_ |
1653 | * of an escape sequence. | 1653 | * of an escape sequence. |
1654 | */ | 1654 | */ |
1655 | if (vc->vc_state == ESosc && c>=8 && c<=13) /* ... except for OSC */ | ||
1656 | return; | ||
1655 | switch (c) { | 1657 | switch (c) { |
1656 | case 0: | 1658 | case 0: |
1657 | return; | 1659 | return; |
1658 | case 7: | 1660 | case 7: |
1659 | if (vc->vc_bell_duration) | 1661 | if (vc->vc_state == ESosc) |
1662 | vc->vc_state = ESnormal; | ||
1663 | else if (vc->vc_bell_duration) | ||
1660 | kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration); | 1664 | kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration); |
1661 | return; | 1665 | return; |
1662 | case 8: | 1666 | case 8: |
@@ -1767,7 +1771,9 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) | |||
1767 | } else if (c=='R') { /* reset palette */ | 1771 | } else if (c=='R') { /* reset palette */ |
1768 | reset_palette(vc); | 1772 | reset_palette(vc); |
1769 | vc->vc_state = ESnormal; | 1773 | vc->vc_state = ESnormal; |
1770 | } else | 1774 | } else if (c>='0' && c<='9') |
1775 | vc->vc_state = ESosc; | ||
1776 | else | ||
1771 | vc->vc_state = ESnormal; | 1777 | vc->vc_state = ESnormal; |
1772 | return; | 1778 | return; |
1773 | case ESpalette: | 1779 | case ESpalette: |
@@ -2021,6 +2027,8 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) | |||
2021 | vc->vc_translate = set_translate(vc->vc_G1_charset, vc); | 2027 | vc->vc_translate = set_translate(vc->vc_G1_charset, vc); |
2022 | vc->vc_state = ESnormal; | 2028 | vc->vc_state = ESnormal; |
2023 | return; | 2029 | return; |
2030 | case ESosc: | ||
2031 | return; | ||
2024 | default: | 2032 | default: |
2025 | vc->vc_state = ESnormal; | 2033 | vc->vc_state = ESnormal; |
2026 | } | 2034 | } |