summaryrefslogtreecommitdiffstats
path: root/autocrypt
diff options
context:
space:
mode:
authorNora Widdecke <nora@sequoia-pgp.org>2021-08-27 11:19:57 +0200
committerNora Widdecke <nora@sequoia-pgp.org>2021-08-27 11:42:52 +0200
commit316552ecabe7bb59978a2f31213b246cbd572e88 (patch)
tree16f80795781f91928155e9b42645aa34fb8c86f6 /autocrypt
parent6562801f39f0839cb35be85c4bb7be803a2b3c1d (diff)
autocrypt: Fix crash the autocrypt header parser.
- Fixes #743.
Diffstat (limited to 'autocrypt')
-rw-r--r--autocrypt/src/lib.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/autocrypt/src/lib.rs b/autocrypt/src/lib.rs
index 3c8c5cb0..aa82aed8 100644
--- a/autocrypt/src/lib.rs
+++ b/autocrypt/src/lib.rs
@@ -250,8 +250,9 @@ impl AutocryptHeaders {
//
// See https://tools.ietf.org/html/rfc5322#section-2.2.3
while let Some(Ok(nl)) = next_line {
- if !nl.is_empty() && (&nl[0..1] == " " || &nl[0..1] == "\t") {
- line.push_str(&nl[..]);
+ if !nl.is_empty() && (nl.starts_with(|c| c == ' ' || c == '\t'))
+ {
+ line.push_str(&nl);
next_line = lines.next();
} else {
// Put it back.
@@ -1103,4 +1104,27 @@ mod test {
&b"Testy McTestface <testy@example.org>"[..]);
Ok(())
}
+
+ /// Demonstrates a panic in the AutocryptHeader parser.
+ #[test]
+ fn issue_743() {
+ let data: Vec<u8> = vec![
+ 0x41, 0x75, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x0a, 0xc4,
+ 0x83, 0x40, 0x39, 0x0a, 0x38, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
+ 0x20, 0x74, 0x6f, 0x63, 0x72, 0x79, 0x70, 0x74, 0x3a, 0x00, 0x00,
+ 0x0a, 0x0a, 0x0a, 0x0a, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x35, 0x39, 0x33, 0x35, 0x38, 0x36, 0x34, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x3e, 0x3f, 0x00, 0x08, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x3e, 0x08,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x01, 0x08, 0x00,
+ 0x00, 0x41, 0x75, 0x74, 0x6f, 0x63, 0x72, 0x79, 0x20, 0x02, 0x01,
+ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x70,
+ ];
+ let _ = AutocryptHeaders::from_bytes(&data);
+ }
}