stalwartlabs / mail-auth

DKIM, ARC, SPF and DMARC library for Rust
https://docs.rs/mail-auth/
Apache License 2.0
82 stars 13 forks source link

IPv6 parsing bug in SPF parser #32

Closed Miesvanderlippe closed 2 months ago

Miesvanderlippe commented 2 months ago

Hey,

Sorry to bug you with another issue but I ran in to an interesting case parsing IPv6 addresses in SPF records. When I try to parse a record including an ipv6 with seven sections and one :: it fails to parse the record.

Here is some minimal code to reproduce the issue:

use mail_auth::{
    common::parse::TxtRecordParser,
    spf::Spf,
};

fn main() {
    let examples = vec![
        // Two sections filled in, six to assume 0000    
        "v=spf1 ip6:fe80::1 -all",
        // Three sections filled in, five to assume 0000    
        "v=spf1 ip6:fe80::0000:1 -all",
        // Four sections filled in, four to assume 0000    
        "v=spf1 ip6:fe80:0000::0000:1 -all",
        // Five sections filled in, three to assume 0000    
        "v=spf1 ip6:fe80:0000:0000:0000::1 -all",
        // Six sections filled in, two to assume 0000
        "v=spf1 ip6:fe80:0000:0000:0000::0000:1 -all",
        // Seven sections filled in, one to assume 0000    
        "v=spf1 ip6:fe80:0000:0000::0000:0000:0000:1 -all",
        // Seven sections filled in, one to assume 0000    
        "v=spf1 ip6:fe80::0000:0000:0000:0000:0000:1 -all",
        // Eight sections filled in, nothing to assume    
        "v=spf1 ip6:fe80:0000:0000:0000:0000:0000:0000:1 -all",
    ];

    for ipv6_spf in examples {
        println!("Parsing {}", ipv6_spf);
        match Spf::parse(ipv6_spf.as_bytes()) {
            Ok(policy) => println!("{:?}", policy),
            Err(error) => println!("{:?}", error),
        };
    }
}
mdecimus commented 2 months ago

Hi, bug reports never bug me ;-) I've just fixed this and published version 0.4.2.