forge
Explore
Log in

Don't you dare go Hollow

config: Fix panic on a bind key with a null byte

Browse files at this commit

66a03cfbfb3172cad09f7dfc56998a9cca897ab4Ivan MolodetskikhParent: e19df12
keysym_from_name() calls CString::new(key).unwrap().
niri-config/src/binds.rsmodified+10 -0
@@ -953,6 +953,10 @@ impl FromStr for Key {
953953 type Err = miette::Error;
954954
955955 fn from_str(s: &str) -> Result<Self, Self::Err> {
956+ if s.contains('\0') {
957+ return Err(miette!("invalid key with a null byte: {s:?}"));
958+ }
959+
956960 let mut modifiers = Modifiers::empty();
957961
958962 let mut split = s.split('+');
@@ -1115,4 +1119,10 @@ mod tests {
11151119 },
11161120 );
11171121 }
1122+
1123+ #[test]
1124+ fn null_byte() {
1125+ // Shouldn't panic.
1126+ let _ = "W\0".parse::<Key>();
1127+ }
11181128 }