Fix static address-list lookup return
authorJeremy Harris <jgh146exb@wizmail.org>
Thu, 10 Mar 2022 20:27:49 +0000 (20:27 +0000)
committerJeremy Harris <jgh146exb@wizmail.org>
Thu, 10 Mar 2022 21:55:08 +0000 (21:55 +0000)
doc/doc-txt/ChangeLog
src/src/match.c
test/stderr/0021
test/stderr/0279

index 02943dd9935231820318f5b4edc4463392e07b71..5ba587b8e5c538addbd023478652612ecefacd33 100644 (file)
@@ -92,6 +92,9 @@ JH/20 When built with NDBM for hints DB's check for nonexistence of a name
 JH/21 Remove the "allow_insecure_tainted_data" main config option and the
       "taint" log_selector.  These were previously deprecated.
 
+JH/22 Fix static address-list lookups to properly return the matched item.
+      Previously only the domain part was returned.
+
 
 Exim version 4.95
 -----------------
index a1ec5616b975a374862f913fdebbd569b2e4117a..0d2cdb57d8399a9f1a8478414ec387527f328cf1 100644 (file)
@@ -1005,15 +1005,16 @@ Returns:         OK     for a match
 static int
 check_address(void *arg, const uschar *pattern, const uschar **valueptr, uschar **error)
 {
-check_address_block *cb = (check_address_block *)arg;
+check_address_block * cb = (check_address_block *)arg;
 check_string_block csb;
 int rc;
 int expand_inc = 0;
-unsigned int *null = NULL;
-const uschar *listptr;
-uschar *subject = cb->address;
-const uschar *s;
-uschar *pdomain, *sdomain;
+unsigned int * null = NULL;
+const uschar * listptr;
+uschar * subject = cb->address;
+const uschar * s;
+uschar * pdomain, * sdomain;
+uschar * value = NULL;
 
 DEBUG(D_lists) debug_printf_indent("address match test: subject=%s pattern=%s\n",
   subject, pattern);
@@ -1064,7 +1065,7 @@ if (*s == ';')
 because other patterns expect to have a local part and a domain to match
 against. */
 
-if (*subject == 0) return (*pattern == 0)? OK : FAIL;
+if (!*subject) return *pattern ? FAIL : OK;
 
 /* If the pattern starts with "@@" we have a split lookup, where the domain is
 looked up to obtain a list of local parts. If the subject's local part is just
@@ -1186,6 +1187,7 @@ if (pdomain != NULL)
       expand_nlength[cb->expand_setup] = sllen - cllen;
       expand_inc = 1;
       }
+    value = string_copyn(pattern + 1, cllen);
     }
   else
     {
@@ -1194,6 +1196,7 @@ if (pdomain != NULL)
         ? strncmpic(subject, pattern, sllen) != 0
        : Ustrncmp(subject, pattern, sllen) != 0) return FAIL;
     }
+    value = string_copyn(pattern, sllen);
   }
 
 /* If the local part matched, or was not being checked, check the domain using
@@ -1218,16 +1221,23 @@ csb.at_is_special = TRUE;
 listptr = pdomain ? pdomain + 1 : pattern;
 if (valueptr) *valueptr = NULL;
 
-return match_check_list(
-  &listptr,                  /* list of one item */
-  UCHAR_MAX+1,               /* impossible separator; single item */
-  &domainlist_anchor,        /* it's a domain list */
-  &null,                     /* ptr to NULL means no caching */
-  check_string,              /* the function to do one test */
-  &csb,                      /* its data */
-  MCL_DOMAIN + MCL_NOEXPAND, /* domain list; don't expand */
-  csb.subject,               /* string for messages */
-  valueptr);                 /* where to pass back lookup data */
+  {
+  const uschar * dvalue = NULL;
+  rc = match_check_list(
+    &listptr,                  /* list of one item */
+    UCHAR_MAX+1,               /* impossible separator; single item */
+    &domainlist_anchor,        /* it's a domain list */
+    &null,                     /* ptr to NULL means no caching */
+    check_string,              /* the function to do one test */
+    &csb,                      /* its data */
+    MCL_DOMAIN + MCL_NOEXPAND, /* domain list; don't expand */
+    csb.subject,               /* string for messages */
+    &dvalue);                       /* where to pass back lookup data */
+  if (valueptr && (value || dvalue))
+    *valueptr = string_sprintf("%s@%s",
+                 value ? value : US"", dvalue ? dvalue : US"");
+  }
+return rc;
 }
 
 
index b476c0340cd662a79440c230770b1f4177b91acd..1b1f6a6055afb83d016a692ac90225661715252c 100644 (file)
@@ -78,7 +78,7 @@ test1 in "somewhere"? no (end of list)
 address match test: subject=ok@test1 pattern=ok@test1
 test1 in "test1"? yes (matched "test1")
 ok@test1 in "ok@somewhere : ok@test1 : ok@test3"? yes (matched "ok@test1")
-data from lookup saved for cache for +ok_senders: key 'ok@test1' value 'test1'
+data from lookup saved for cache for +ok_senders: key 'ok@test1' value 'ok@test1'
 ok@test1 in "+ok_senders"? yes (matched "+ok_senders")
 check sender_domains = +ok_sender_domains
 test1 in "somewhere : test1 : test3"? yes (matched "test1")
@@ -93,7 +93,7 @@ using ACL "rcpt"
 processing "accept" (TESTSUITE/test-config 70)
 check senders = +ok_senders
 cached yes match for +ok_senders
-cached lookup data = test1
+cached lookup data = ok@test1
 ok@test1 in "+ok_senders"? yes (matched "+ok_senders" - cached)
 check sender_domains = +ok_sender_domains
 cached yes match for +ok_sender_domains
@@ -175,7 +175,7 @@ test3 in "test1"? no (end of list)
 address match test: subject=ok@test3 pattern=ok@test3
 test3 in "test3"? yes (matched "test3")
 ok@test3 in "ok@somewhere : ok@test1 : ok@test3"? yes (matched "ok@test3")
-data from lookup saved for cache for +ok_senders: key 'ok@test3' value 'test3'
+data from lookup saved for cache for +ok_senders: key 'ok@test3' value 'ok@test3'
 ok@test3 in "+ok_senders"? yes (matched "+ok_senders")
 check sender_domains = +ok_sender_domains
 test3 in "somewhere : test1 : test3"? yes (matched "test3")
index b42f8acc7d41ee97a6a9c90c24c3b8f4b87a9e0c..d61b7fb8ec50a2c7eb6b9441fee8ccc14265313b 100644 (file)
@@ -34,7 +34,7 @@ CALLER@test.ex in "never1@test.ex"? no (end of list)
 address match test: subject=CALLER@test.ex pattern=CALLER@test.ex
 test.ex in "test.ex"? yes (matched "test.ex")
 CALLER@test.ex in "CALLER@test.ex"? yes (matched "CALLER@test.ex")
-data from lookup saved for cache for +local_addresses: key 'CALLER@test.ex' value 'test.ex'
+data from lookup saved for cache for +local_addresses: key 'CALLER@test.ex' value 'CALLER@test.ex'
 CALLER@test.ex in "+never_addresses : +n1_addresses : ! +local_addresses"? no (matched "! +local_addresses")
 r1 router skipped: senders mismatch
 --------> r2 router <--------
@@ -47,7 +47,7 @@ cached no match for +n1_addresses
 cached lookup data = NULL
 CALLER@test.ex in "<; never2@test.ex ; +n1_addresses"? no (end of list)
 cached yes match for +local_addresses
-cached lookup data = test.ex
+cached lookup data = CALLER@test.ex
 CALLER@test.ex in "+never_addresses : +n2_addresses : !+local_addresses"? no (matched "!+local_addresses" - cached)
 r2 router skipped: senders mismatch
 --------> r3 router <--------
@@ -57,7 +57,7 @@ seeking password data for user "CALLER": using cached result
 getpwnam() succeeded uid=CALLER_UID gid=CALLER_GID
 checking senders
 cached yes match for +local_addresses
-cached lookup data = test.ex
+cached lookup data = CALLER@test.ex
 CALLER@test.ex in "+local_addresses"? yes (matched "+local_addresses" - cached)
 calling r3 router
 r3 router called for CALLER@test.ex