From: Jeremy Harris Date: Thu, 11 Apr 2024 10:53:24 +0000 (+0100) Subject: Use compressed form of ipv6 in $sender_host_address under -bh. Bug 3027 X-Git-Tag: exim-4.98-RC0~43 X-Git-Url: https://git.exim.org/exim.git/commitdiff_plain/e4cdc6558fcf05e3923442ec7831adbe58c3e7a7 Use compressed form of ipv6 in $sender_host_address under -bh. Bug 3027 --- diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog index af4678913..98c7a9584 100644 --- a/doc/doc-txt/ChangeLog +++ b/doc/doc-txt/ChangeLog @@ -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 ----------------- diff --git a/src/src/exim.c b/src/src/exim.c index 5c9e64021..040df2cd0 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -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 +*/ diff --git a/src/src/functions.h b/src/src/functions.h index 9f6396a17..f0b600ccc 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -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 *); diff --git a/src/src/host.c b/src/src/host.c index 08e946548..381f2a5fc 100644 --- a/src/src/host.c +++ b/src/src/host.c @@ -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);