Commit
Author: mdecimus [mauro@stalw.art]
Hash: fd6b5f73736935ec59e5295f4efb9d8e18a6b92c
Timestamp: Wed, 29 May 2024 16:13:44 +0000 (5 months ago)

+35 -2 +/-3 browse
IPv6 parsing bug in SPF parser (fixes #32)
1diff --git a/CHANGELOG.md b/CHANGELOG.md
2index dcdc705..0c8c695 100644
3--- a/CHANGELOG.md
4+++ b/CHANGELOG.md
5 @@ -1,3 +1,7 @@
6+ mail-auth 0.4.2
7+ ================================
8+ - Fix: IPv6 parsing bug in SPF parser (#32)
9+
10 mail-auth 0.4.1
11 ================================
12 - Bump `zip` dependency to 2.1.1.
13 diff --git a/Cargo.toml b/Cargo.toml
14index 78c2199..617cad5 100644
15--- a/Cargo.toml
16+++ b/Cargo.toml
17 @@ -1,7 +1,7 @@
18 [package]
19 name = "mail-auth"
20 description = "DKIM, ARC, SPF and DMARC library for Rust"
21- version = "0.4.1"
22+ version = "0.4.2"
23 edition = "2021"
24 authors = [ "Stalwart Labs <hello@stalw.art>"]
25 license = "Apache-2.0 OR MIT"
26 diff --git a/src/spf/parse.rs b/src/spf/parse.rs
27index c1f82bf..577d342 100644
28--- a/src/spf/parse.rs
29+++ b/src/spf/parse.rs
30 @@ -528,7 +528,7 @@ impl SPFParser for Iter<'_, u8> {
31 }
32 }
33 if zero_group_pos != usize::MAX && zero_group_pos < ip_pos {
34- if ip_pos < 7 {
35+ if ip_pos <= 7 {
36 ip.copy_within(zero_group_pos..ip_pos, zero_group_pos + 8 - ip_pos);
37 ip[zero_group_pos..zero_group_pos + 8 - ip_pos].fill(0);
38 } else {
39 @@ -1447,6 +1447,27 @@ mod test {
40 ],
41 },
42 ),
43+ (
44+ concat!("v=spf1 ip6:fe80:0000:0000::0000:0000:0000:1 -all"),
45+ Spf {
46+ version: Version::V1,
47+ ra: None,
48+ rp: 100,
49+ rr: u8::MAX,
50+ exp: None,
51+ redirect: None,
52+ directives: vec![
53+ Directive::new(
54+ Qualifier::Pass,
55+ Mechanism::Ip6 {
56+ addr: "fe80:0000:0000::0000:0000:0000:1".parse().unwrap(),
57+ mask: u128::MAX,
58+ },
59+ ),
60+ Directive::new(Qualifier::Fail, Mechanism::All),
61+ ],
62+ },
63+ ),
64 ] {
65 assert_eq!(
66 Spf::parse(record.as_bytes()).unwrap_or_else(|err| panic!("{record:?} : {err:?}")),
67 @@ -1478,6 +1499,14 @@ mod test {
68 "0:0:0:0:0:FFFF:129.144.52.38",
69 "::13.1.68.3",
70 "::FFFF:129.144.52.38",
71+ "fe80::1",
72+ "fe80::0000:1",
73+ "fe80:0000::0000:1",
74+ "fe80:0000:0000:0000::1",
75+ "fe80:0000:0000:0000::0000:1",
76+ "fe80:0000:0000::0000:0000:0000:1",
77+ "fe80::0000:0000:0000:0000:0000:1",
78+ "fe80:0000:0000:0000:0000:0000:0000:1",
79 ] {
80 for test in [test.to_string(), format!("{test} ")] {
81 let (ip, stop_char) = test