summaryrefslogtreecommitdiff
path: root/alacritty_terminal
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2020-12-17 01:05:40 +0000
committerGitHub <noreply@github.com>2020-12-17 01:05:40 +0000
commitc065c5f2f9c1ab0bf2c2ff27b64f4a4a51542e16 (patch)
tree4726ef87953155f2eedb7c5738f849e56df0c80b /alacritty_terminal
parent1e9b550f447bb4e1caf1e5ad36f760f1ef869b25 (diff)
downloadalacritty-c065c5f2f9c1ab0bf2c2ff27b64f4a4a51542e16.tar.gz
alacritty-c065c5f2f9c1ab0bf2c2ff27b64f4a4a51542e16.zip
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.
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/ansi.rs44
1 files changed, 22 insertions, 22 deletions
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs
index 4c50495c..21f0ec45 100644
--- a/alacritty_terminal/src/ansi.rs
+++ b/alacritty_terminal/src/ansi.rs
@@ -1131,12 +1131,12 @@ where
}
macro_rules! configure_charset {
- ($charset:path, $intermediate:expr) => {{
- let index: CharsetIndex = match $intermediate {
- Some(b'(') => CharsetIndex::G0,
- Some(b')') => CharsetIndex::G1,
- Some(b'*') => CharsetIndex::G2,
- Some(b'+') => CharsetIndex::G3,
+ ($charset:path, $intermediates:expr) => {{
+ let index: CharsetIndex = match $intermediates {
+ [b'('] => CharsetIndex::G0,
+ [b')'] => CharsetIndex::G1,
+ [b'*'] => CharsetIndex::G2,
+ [b'+'] => CharsetIndex::G3,
_ => {
unhandled!();
return;
@@ -1146,27 +1146,27 @@ where
}};
}
- match (byte, intermediates.get(0)) {
- (b'B', intermediate) => configure_charset!(StandardCharset::Ascii, intermediate),
- (b'D', None) => self.handler.linefeed(),
- (b'E', None) => {
+ match (byte, intermediates) {
+ (b'B', intermediates) => configure_charset!(StandardCharset::Ascii, intermediates),
+ (b'D', []) => self.handler.linefeed(),
+ (b'E', []) => {
self.handler.linefeed();
self.handler.carriage_return();
},
- (b'H', None) => self.handler.set_horizontal_tabstop(),
- (b'M', None) => self.handler.reverse_index(),
- (b'Z', None) => self.handler.identify_terminal(self.writer, None),
- (b'c', None) => self.handler.reset_state(),
- (b'0', intermediate) => {
- configure_charset!(StandardCharset::SpecialCharacterAndLineDrawing, intermediate)
+ (b'H', []) => self.handler.set_horizontal_tabstop(),
+ (b'M', []) => self.handler.reverse_index(),
+ (b'Z', []) => self.handler.identify_terminal(self.writer, None),
+ (b'c', []) => self.handler.reset_state(),
+ (b'0', intermediates) => {
+ configure_charset!(StandardCharset::SpecialCharacterAndLineDrawing, intermediates)
},
- (b'7', None) => self.handler.save_cursor_position(),
- (b'8', Some(b'#')) => self.handler.decaln(),
- (b'8', None) => self.handler.restore_cursor_position(),
- (b'=', None) => self.handler.set_keypad_application_mode(),
- (b'>', None) => self.handler.unset_keypad_application_mode(),
+ (b'7', []) => self.handler.save_cursor_position(),
+ (b'8', [b'#']) => self.handler.decaln(),
+ (b'8', []) => self.handler.restore_cursor_position(),
+ (b'=', []) => self.handler.set_keypad_application_mode(),
+ (b'>', []) => self.handler.unset_keypad_application_mode(),
// String terminator, do nothing (parser handles as string terminator).
- (b'\\', None) => (),
+ (b'\\', []) => (),
_ => unhandled!(),
}
}