aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Chibisov <wchibisovkirill@gmail.com>2019-09-26 15:44:59 +0300
committerChristian Duerr <contact@christianduerr.com>2019-09-26 14:44:59 +0200
commitad24485cdb5a2b6559185c3c41adbf6852e5ac80 (patch)
tree549c7f44d03b3bf6668406ab1d73f5660d73dd69
parentc1f089970fd3d4b9137d07647f8cd028b2b5b3a9 (diff)
downloadalacritty-ad24485cdb5a2b6559185c3c41adbf6852e5ac80.tar.gz
alacritty-ad24485cdb5a2b6559185c3c41adbf6852e5ac80.zip
Fix overflow on wrong scroll region setting
Fixes #2822.
-rw-r--r--CHANGELOG.md1
-rw-r--r--alacritty_terminal/src/ansi.rs17
-rw-r--r--alacritty_terminal/src/term/mod.rs24
-rw-r--r--alacritty_terminal/src/window.rs2
4 files changed, 25 insertions, 19 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f47a0135..fd802b39 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Wayland primary selection clipboard not storing text when selection is stopped outside of the window
- Block URL highlight while a selection is active
- Bindings for Alt + F1-F12
+- Discard scrolling region escape with bottom above top
### Removed
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs
index f95dc356..69391617 100644
--- a/alacritty_terminal/src/ansi.rs
+++ b/alacritty_terminal/src/ansi.rs
@@ -14,7 +14,6 @@
//
//! ANSI Terminal Stream Parsing
use std::io;
-use std::ops::Range;
use std::str;
use crate::index::{Column, Contains, Line};
@@ -296,7 +295,7 @@ pub trait Handler {
fn unset_mode(&mut self, _: Mode) {}
/// DECSTBM - Set the terminal scrolling region
- fn set_scrolling_region(&mut self, _: Range<Line>) {}
+ fn set_scrolling_region(&mut self, _top: usize, _bottom: usize) {}
/// DECKPAM - Set keypad to applications mode (ESCape instead of digits)
fn set_keypad_application_mode(&mut self) {}
@@ -1079,16 +1078,10 @@ where
handler.set_cursor_style(style);
},
('r', None) => {
- let arg0 = arg_or_default!(idx: 0, default: 1) as usize;
- let top = Line(arg0 - 1);
- // Bottom should be included in the range, but range end is not
- // usually included. One option would be to use an inclusive
- // range, but instead we just let the open range end be 1
- // higher.
- let arg1 = arg_or_default!(idx: 1, default: handler.lines().0 as _) as usize;
- let bottom = Line(arg1);
-
- handler.set_scrolling_region(top..bottom);
+ let top = arg_or_default!(idx: 0, default: 1) as usize;
+ let bottom = arg_or_default!(idx: 1, default: handler.lines().0 as _) as usize;
+
+ handler.set_scrolling_region(top, bottom);
},
('s', None) => handler.save_cursor_position(),
('u', None) => handler.restore_cursor_position(),
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index 11e0af45..6829c7d0 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -1260,8 +1260,7 @@ impl Term {
fn deccolm(&mut self) {
// Setting 132 column font makes no sense, but run the other side effects
// Clear scrolling region
- let scroll_region = Line(0)..self.grid.num_lines();
- self.set_scrolling_region(scroll_region);
+ self.set_scrolling_region(1, self.grid.num_lines().0);
// Clear grid
let template = self.cursor.template;
@@ -2118,10 +2117,23 @@ impl ansi::Handler for Term {
}
#[inline]
- fn set_scrolling_region(&mut self, region: Range<Line>) {
- trace!("Setting scrolling region: {:?}", region);
- self.scroll_region.start = min(region.start, self.grid.num_lines());
- self.scroll_region.end = min(region.end, self.grid.num_lines());
+ fn set_scrolling_region(&mut self, top: usize, bottom: usize) {
+ if top >= bottom {
+ debug!("Invalid scrolling region: ({};{})", top, bottom);
+ return;
+ }
+
+ // Bottom should be included in the range, but range end is not
+ // usually included. One option would be to use an inclusive
+ // range, but instead we just let the open range end be 1
+ // higher.
+ let start = Line(top - 1);
+ let end = Line(bottom);
+
+ trace!("Setting scrolling region: ({};{})", start, end);
+
+ self.scroll_region.start = min(start, self.grid.num_lines());
+ self.scroll_region.end = min(end, self.grid.num_lines());
self.goto(Line(0), Column(0));
}
diff --git a/alacritty_terminal/src/window.rs b/alacritty_terminal/src/window.rs
index 3e3f47f7..f18fda3a 100644
--- a/alacritty_terminal/src/window.rs
+++ b/alacritty_terminal/src/window.rs
@@ -32,7 +32,7 @@ use glutin::{
#[cfg(not(target_os = "macos"))]
use image::ImageFormat;
#[cfg(not(any(target_os = "macos", windows)))]
-use x11_dl::xlib::{Xlib, Display as XDisplay, PropModeReplace, XErrorEvent};
+use x11_dl::xlib::{Display as XDisplay, PropModeReplace, XErrorEvent, Xlib};
use crate::config::{Config, Decorations, StartupMode, WindowConfig};
use crate::gl;