Skip to content

Commit

Permalink
IPv6 parsing bug in SPF parser (fixes #32)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed May 29, 2024
1 parent 0491a09 commit fd6b5f7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
mail-auth 0.4.2
================================
- Fix: IPv6 parsing bug in SPF parser (#32)

mail-auth 0.4.1
================================
- Bump `zip` dependency to 2.1.1.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mail-auth"
description = "DKIM, ARC, SPF and DMARC library for Rust"
version = "0.4.1"
version = "0.4.2"
edition = "2021"
authors = [ "Stalwart Labs <[email protected]>"]
license = "Apache-2.0 OR MIT"
Expand Down
31 changes: 30 additions & 1 deletion src/spf/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl SPFParser for Iter<'_, u8> {
}
}
if zero_group_pos != usize::MAX && zero_group_pos < ip_pos {
if ip_pos < 7 {
if ip_pos <= 7 {
ip.copy_within(zero_group_pos..ip_pos, zero_group_pos + 8 - ip_pos);
ip[zero_group_pos..zero_group_pos + 8 - ip_pos].fill(0);
} else {
Expand Down Expand Up @@ -1447,6 +1447,27 @@ mod test {
],
},
),
(
concat!("v=spf1 ip6:fe80:0000:0000::0000:0000:0000:1 -all"),
Spf {
version: Version::V1,
ra: None,
rp: 100,
rr: u8::MAX,
exp: None,
redirect: None,
directives: vec![
Directive::new(
Qualifier::Pass,
Mechanism::Ip6 {
addr: "fe80:0000:0000::0000:0000:0000:1".parse().unwrap(),
mask: u128::MAX,
},
),
Directive::new(Qualifier::Fail, Mechanism::All),
],
},
),
] {
assert_eq!(
Spf::parse(record.as_bytes()).unwrap_or_else(|err| panic!("{record:?} : {err:?}")),
Expand Down Expand Up @@ -1478,6 +1499,14 @@ mod test {
"0:0:0:0:0:FFFF:129.144.52.38",
"::13.1.68.3",
"::FFFF:129.144.52.38",
"fe80::1",
"fe80::0000:1",
"fe80:0000::0000:1",
"fe80:0000:0000:0000::1",
"fe80:0000:0000:0000::0000:1",
"fe80:0000:0000::0000:0000:0000:1",
"fe80::0000:0000:0000:0000:0000:1",
"fe80:0000:0000:0000:0000:0000:0000:1",
] {
for test in [test.to_string(), format!("{test} ")] {
let (ip, stop_char) = test
Expand Down

0 comments on commit fd6b5f7

Please sign in to comment.