aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2017-05-29 21:22:38 -0400
committerJoe Wilm <jwilm@users.noreply.github.com>2017-05-29 18:55:35 -0700
commit56f76600ff240d17ead0592ca228b655d256f769 (patch)
tree4e1bebaede40a77c0463bd3d9461e9d21de614d2
parent2910bd0cec3c1b67f8b4e052d1865bb31a626a45 (diff)
downloadr-alacritty-vte-56f76600ff240d17ead0592ca228b655d256f769.tar.gz
r-alacritty-vte-56f76600ff240d17ead0592ca228b655d256f769.tar.bz2
r-alacritty-vte-56f76600ff240d17ead0592ca228b655d256f769.zip
Properly handle maximum number of CSI params
This commit ensures that 'num_params' is never incremented beyond MAX_PARAMS. Additionally, an extra parameter is added to the corresponding OSC test (17 params or MAX_PARAMS + 1) to ensure that the proper behavior is tested.
-rw-r--r--src/lib.rs37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 97d4c4f..02c7996 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -329,6 +329,11 @@ impl Parser {
if byte == b';' {
// Completed a param
let idx = self.num_params;
+
+ if idx == MAX_PARAMS {
+ return;
+ }
+
self.params[idx] = self.param;
self.param = 0;
self.num_params += 1;
@@ -442,6 +447,7 @@ mod tests {
#[derive(Default)]
struct CsiDispatcher {
+ dispatched_csi: bool,
params: Vec<Vec<i64>>,
}
@@ -453,6 +459,7 @@ mod tests {
fn unhook(&mut self) {}
fn osc_dispatch(&mut self, _params: &[&[u8]]) { }
fn csi_dispatch(&mut self, params: &[i64], _intermediates: &[u8], _ignore: bool, _c: char) {
+ self.dispatched_csi = true;
self.params.push(params.to_vec());
}
fn esc_dispatch(&mut self, _params: &[i64], _intermediates: &[u8], _ignore: bool, _byte: u8) {}
@@ -498,7 +505,7 @@ mod tests {
fn parse_osc_max_params() {
use MAX_PARAMS;
- static INPUT: &'static [u8] = b"\x1b];;;;;;;;;;;;;;;;\x1b";
+ static INPUT: &'static [u8] = b"\x1b];;;;;;;;;;;;;;;;;\x1b";
// Create dispatcher and check state
let mut dispatcher = OscDispatcher::default();
@@ -520,10 +527,34 @@ mod tests {
}
#[test]
+ fn parse_csi_max_params() {
+ use MAX_PARAMS;
+
+ static INPUT: &'static [u8] = b"\x1b[;;;;;;;;;;;;;;;;;p";
+
+ // Create dispatcher and check state
+ let mut dispatcher = CsiDispatcher::default();
+ assert!(!dispatcher.dispatched_csi);
+
+
+ // Run parser using OSC_BYTES
+ let mut parser = Parser::new();
+ for byte in INPUT {
+ parser.advance(&mut dispatcher, *byte);
+ }
+
+ // Check that flag is set and thus csi_dispatch assertions ran.
+ assert!(dispatcher.dispatched_csi);
+ assert_eq!(dispatcher.params.len(), 1);
+ assert_eq!(dispatcher.params[0].len(), MAX_PARAMS);
+
+ }
+
+ #[test]
fn parse_semi_set_underline() {
// Create dispatcher and check state
- let mut dispatcher = CsiDispatcher { params: vec![] };
+ let mut dispatcher = CsiDispatcher::default();
// Run parser using OSC_BYTES
let mut parser = Parser::new();
@@ -540,7 +571,7 @@ mod tests {
// The important part is the parameter, which is (i64::MAX + 1)
static INPUT: &'static [u8] = b"\x1b[9223372036854775808m";
- let mut dispatcher = CsiDispatcher { params: vec![] };
+ let mut dispatcher = CsiDispatcher::default();
let mut parser = Parser::new();
for byte in INPUT {