1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-11 13:51:01 -05:00

Fix invalid ESC escape sequence parsing

This strictens the ESC escape sequence parser to prevent invalid
intermediates from being ignored. Previously the parser would just look
at the first intermediate without validating that the rest of them is
empty.

If an escape like `\e(#0` is used now, it will no longer be accepted as
`\e(0` since the intermediate `#` is also present.
This commit is contained in:
Christian Duerr 2020-12-17 01:05:40 +00:00 committed by GitHub
parent 1e9b550f44
commit c065c5f2f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 22 deletions

View file

@ -37,6 +37,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- No live config update when starting Alacritty with a broken configuration file - No live config update when starting Alacritty with a broken configuration file
- PTY not drained to the end with the `--hold` flag enabled - PTY not drained to the end with the `--hold` flag enabled
- High CPU usage on BSD with live config reload enabled - High CPU usage on BSD with live config reload enabled
- Alacritty not discarding invalid escape sequences starting with ESC
### Removed ### Removed

View file

@ -1131,12 +1131,12 @@ where
} }
macro_rules! configure_charset { macro_rules! configure_charset {
($charset:path, $intermediate:expr) => {{ ($charset:path, $intermediates:expr) => {{
let index: CharsetIndex = match $intermediate { let index: CharsetIndex = match $intermediates {
Some(b'(') => CharsetIndex::G0, [b'('] => CharsetIndex::G0,
Some(b')') => CharsetIndex::G1, [b')'] => CharsetIndex::G1,
Some(b'*') => CharsetIndex::G2, [b'*'] => CharsetIndex::G2,
Some(b'+') => CharsetIndex::G3, [b'+'] => CharsetIndex::G3,
_ => { _ => {
unhandled!(); unhandled!();
return; return;
@ -1146,27 +1146,27 @@ where
}}; }};
} }
match (byte, intermediates.get(0)) { match (byte, intermediates) {
(b'B', intermediate) => configure_charset!(StandardCharset::Ascii, intermediate), (b'B', intermediates) => configure_charset!(StandardCharset::Ascii, intermediates),
(b'D', None) => self.handler.linefeed(), (b'D', []) => self.handler.linefeed(),
(b'E', None) => { (b'E', []) => {
self.handler.linefeed(); self.handler.linefeed();
self.handler.carriage_return(); self.handler.carriage_return();
}, },
(b'H', None) => self.handler.set_horizontal_tabstop(), (b'H', []) => self.handler.set_horizontal_tabstop(),
(b'M', None) => self.handler.reverse_index(), (b'M', []) => self.handler.reverse_index(),
(b'Z', None) => self.handler.identify_terminal(self.writer, None), (b'Z', []) => self.handler.identify_terminal(self.writer, None),
(b'c', None) => self.handler.reset_state(), (b'c', []) => self.handler.reset_state(),
(b'0', intermediate) => { (b'0', intermediates) => {
configure_charset!(StandardCharset::SpecialCharacterAndLineDrawing, intermediate) configure_charset!(StandardCharset::SpecialCharacterAndLineDrawing, intermediates)
}, },
(b'7', None) => self.handler.save_cursor_position(), (b'7', []) => self.handler.save_cursor_position(),
(b'8', Some(b'#')) => self.handler.decaln(), (b'8', [b'#']) => self.handler.decaln(),
(b'8', None) => self.handler.restore_cursor_position(), (b'8', []) => self.handler.restore_cursor_position(),
(b'=', None) => self.handler.set_keypad_application_mode(), (b'=', []) => self.handler.set_keypad_application_mode(),
(b'>', None) => self.handler.unset_keypad_application_mode(), (b'>', []) => self.handler.unset_keypad_application_mode(),
// String terminator, do nothing (parser handles as string terminator). // String terminator, do nothing (parser handles as string terminator).
(b'\\', None) => (), (b'\\', []) => (),
_ => unhandled!(), _ => unhandled!(),
} }
} }