[pmg-devel] [PATCH v2 pmg-api 1/1] [pmg-api] fix #3098 sort domains by length first

Daniel Berteaud daniel at firewall-services.com
Wed Oct 28 11:20:15 CET 2020


So if we have a sub domain and its parent in the list, the correct one will be returned

Signed-off-by: Daniel Berteaud <daniel at firewall-services.com>
---
 src/PMG/DKIMSign.pm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/PMG/DKIMSign.pm b/src/PMG/DKIMSign.pm
index 7cb06a6..08197f8 100644
--- a/src/PMG/DKIMSign.pm
+++ b/src/PMG/DKIMSign.pm
@@ -69,7 +69,9 @@ sub signing_domain {
     my $dkimdomains = PVE::INotify::read_file('dkimdomains');
     $dkimdomains = PVE::INotify::read_file('domains') if !scalar(%$dkimdomains);
 
-    foreach my $domain (sort keys %$dkimdomains) {
+    # Sort domains by length first, so if we have both a sub domain and its parent
+    # the correct one will be returned
+    foreach my $domain (sort { length($b) <=> length($a) || $a cmp $b} keys %$dkimdomains) {
 	if ( $input_domain =~ /\Q$domain\E$/i ) {
 	    $self->domain($domain);
 	    return 1;
-- 
2.26.2





More information about the pmg-devel mailing list