Use compressed form of ipv6 in $sender_host_address under -bh. Bug 3027 master github/master
authorJeremy Harris <jgh146exb@wizmail.org>
Thu, 11 Apr 2024 10:53:24 +0000 (11:53 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Thu, 11 Apr 2024 10:53:24 +0000 (11:53 +0100)
doc/doc-txt/ChangeLog
src/src/exim.c
src/src/functions.h
src/src/host.c

index af467891374c8e67c19f568a9b4d171181ae584a..98c7a9584097215265dd5fc4d05db2d8dea1816d 100644 (file)
@@ -150,6 +150,11 @@ JH/29 Bug 3087: Fix SRS encode.  A zero-length quoted element in the local-part
 
 JH/30 Bug 3029: Avoid feeding Resent-From: to DMARC.
 
+JH/31 Bug 3027: For -bh / -bhc tests change to using the compressed form of
+      ipv6 addresses for the sender.  Previously the uncompressed form was
+      used, and if used in textual form this would result in behavior difference
+      versus non-bh.
+
 
 Exim version 4.97
 -----------------
index 5c9e640218d9e25154827a973a53af2bf3d7ddd5..040df2cd020aa2cd8b39a226b2ab6a2622e5aa4a 100644 (file)
@@ -2339,9 +2339,9 @@ on the second character (the one after '-'), to save some effort. */
 
        /* -bh: Host checking - an IP address must follow. */
        case 'h':
-         if (!*argrest || Ustrcmp(argrest, "c") == 0)
+         if (  (!*argrest || Ustrcmp(argrest, "c") == 0)
+            && ++i < argc)
            {
-           if (++i >= argc) { badarg = TRUE; break; }
            sender_host_address = string_copy_taint(
                  exim_str_fail_toolong(argv[i], EXIM_IPADDR_MAX, "-bh"),
                  GET_TAINTED);
@@ -2349,7 +2349,8 @@ on the second character (the one after '-'), to save some effort. */
            f.host_checking_callout = *argrest == 'c';
            message_logs = FALSE;
            }
-         else badarg = TRUE;
+         else
+           badarg = TRUE;
          break;
 
        /* -bi: This option is used by sendmail to initialize *the* alias file,
@@ -5443,11 +5444,14 @@ if (host_checking)
     }
 
   /* In case the given address is a non-canonical IPv6 address, canonicalize
-  it. The code works for both IPv4 and IPv6, as it happens. */
+  it. Use the compressed form for IPv6. */
 
   size = host_aton(sender_host_address, x);
   sender_host_address = store_get(48, GET_UNTAINTED);  /* large enough for full IPv6 */
-  (void)host_nmtoa(size, x, -1, sender_host_address, ':');
+  if (size == 1)
+    (void) host_nmtoa(size, x, -1, sender_host_address, ':');
+  else
+    (void) ipv6_nmtoa(x, sender_host_address);
 
   /* Now set up for testing */
 
@@ -6189,3 +6193,5 @@ return 0;                  /* To stop compiler warning */
 
 
 /* End of exim.c */
+/* vi: aw ai sw=2
+*/
index 9f6396a17dfbc41acef0f2510677c563fa85ec7d..f0b600ccc80bc11edbaa54a05b8cc0dd67fd7a8c 100644 (file)
@@ -311,7 +311,7 @@ extern BOOL    host_is_tls_on_connect_port(int);
 extern int     host_item_get_port(host_item *);
 extern void    host_mask(int, int *, int);
 extern int     host_name_lookup(void);
-extern int     host_nmtoa(int, int *, int, uschar *, int);
+extern int     host_nmtoa(int, const int *, int, uschar *, int);
 extern uschar *host_ntoa(int, const void *, uschar *, int *);
 extern int     host_scan_for_local_hosts(host_item *, host_item **, BOOL *);
 
index 08e946548c10d1f00161f8a79c16f4965441bb60..381f2a5fc99c9b4bf11118525a81e5cd233e73fe 100644 (file)
@@ -1061,19 +1061,15 @@ Returns:      the number of characters placed in buffer, not counting
 */
 
 int
-host_nmtoa(int count, int *binary, int mask, uschar *buffer, int sep)
+host_nmtoa(int count, const int * binary, int mask, uschar * buffer, int sep)
 {
-int j;
-uschar *tt = buffer;
+uschar * tt = buffer;
 
 if (count == 1)
-  {
-  j = binary[0];
-  for (int i = 24; i >= 0; i -= 8)
+  for (int j = binary[0], i = 24; i >= 0; i -= 8)
     tt += sprintf(CS tt, "%d.", (j >> i) & 255);
-  }
 else
-  for (int i = 0; i < 4; i++)
+  for (int j, i = 0; i < 4; i++)
     {
     j = binary[i];
     tt += sprintf(CS tt, "%04x%c%04x%c", (j >> 16) & 0xffff, sep, j & 0xffff, sep);