config: Fix panic on a bind key with a null byte
Browse files at this commit66a03cfbfb3172cad09f7dfc56998a9cca897ab4Parent: e19df121 changed file +10 -0
- niri-config/src/binds.rs +10 -0
niri-config/src/binds.rsmodified+10 -0
| @@ -953,6 +953,10 @@ impl FromStr for Key { | |||
| 953 | type Err = miette::Error; | 953 | type Err = miette::Error; |
| 954 | 954 | ||
| 955 | fn from_str(s: &str) -> Result<Self, Self::Err> { | 955 | 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 | + | ||
| 956 | let mut modifiers = Modifiers::empty(); | 960 | let mut modifiers = Modifiers::empty(); |
| 957 | 961 | ||
| 958 | let mut split = s.split('+'); | 962 | let mut split = s.split('+'); |
| @@ -1115,4 +1119,10 @@ mod tests { | |||
| 1115 | }, | 1119 | }, |
| 1116 | ); | 1120 | ); |
| 1117 | } | 1121 | } |
| 1122 | + | ||
| 1123 | + #[test] | ||
| 1124 | + fn null_byte() { | ||
| 1125 | + // Shouldn't panic. | ||
| 1126 | + let _ = "W\0".parse::<Key>(); | ||
| 1127 | + } | ||
| 1118 | } | 1128 | } |