diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-08-27 10:02:08 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-08-27 10:02:08 +0200 |
commit | 6562801f39f0839cb35be85c4bb7be803a2b3c1d (patch) | |
tree | a9cdfc744b315edbf858c905428fa9ed93051fff | |
parent | 8ec54541530b74ff6dfeccd9a675cc15c2d88724 (diff) |
ipc: Fix a crash in the sexp lexer.
- Fixes #742.
-rw-r--r-- | ipc/src/sexp/parse/lexer.rs | 6 | ||||
-rw-r--r-- | ipc/src/sexp/parse/mod.rs | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/ipc/src/sexp/parse/lexer.rs b/ipc/src/sexp/parse/lexer.rs index 0a570475..8d091e25 100644 --- a/ipc/src/sexp/parse/lexer.rs +++ b/ipc/src/sexp/parse/lexer.rs @@ -121,12 +121,14 @@ impl<'input> Iterator for Lexer<'input> { *c as char, &input[..offset])))), } } + + let len = String::from_utf8_lossy(&input); + Some(Err(LexicalError::TruncatedInput( + format!("Expected colon and data after {:?}", len)))) }, _ => return Some(Err(LexicalError::UnexpectedCharacter( format!("Unexpected character {}", *c as char)))), } - - unreachable!() })(&self.input)?; let (l, token) = match len_token { diff --git a/ipc/src/sexp/parse/mod.rs b/ipc/src/sexp/parse/mod.rs index 46905fc3..3e3e077e 100644 --- a/ipc/src/sexp/parse/mod.rs +++ b/ipc/src/sexp/parse/mod.rs @@ -146,4 +146,10 @@ mod tests { assert!(Sexp::from_bytes( crate::tests::file("sexp/rsa-signature.sexp")).is_ok()); } + + /// Demonstrates a crash in the lexer. + #[test] + fn issue_742() { + Sexp::from_bytes(b"7").unwrap_err(); + } } |