fix #5230: sys: net: properly escape FQDN regex

Due to interpolation, the \. sequence must be double-escaped.
Previously, this would result in a non-escaped dot, thus matching much
more liberally than it should.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
 [ TL: fix bug # reference in code comments ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Christoph Heiss 2024-02-15 13:39:38 +01:00 committed by Thomas Lamprecht
parent 1a5665378b
commit f6bea065f7
3 changed files with 10 additions and 1 deletions

View File

@ -7,7 +7,7 @@ use base qw(Exporter);
our @EXPORT_OK = qw(parse_ip_address parse_ip_mask parse_fqdn);
our $HOSTNAME_RE = "(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{,61}?[a-zA-Z0-9])?)";
our $FQDN_RE = "(?:${HOSTNAME_RE}\.)*${HOSTNAME_RE}";
our $FQDN_RE = "(?:${HOSTNAME_RE}\\.)*${HOSTNAME_RE}";
my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";

View File

@ -309,6 +309,12 @@ mod tests {
Fqdn::from(&format!("{}.com", "a".repeat(64))),
Err(InvalidPart("a".repeat(64))),
);
// https://bugzilla.proxmox.com/show_bug.cgi?id=5230
assert_eq!(
Fqdn::from("123@foo.com"),
Err(InvalidPart("123@foo".to_owned()))
);
}
#[test]

View File

@ -51,4 +51,7 @@ is_parsed('a' x 63 . '.com', ['a' x 63, 'com']);
is_invalid('a' x 250 . '.com', ERR_TOOLONG);
is_invalid('a' x 64 . '.com', ERR_ALPHANUM);
# https://bugzilla.proxmox.com/show_bug.cgi?id=5230
is_invalid('123@foo.com', ERR_ALPHANUM);
done_testing();