JH/33 Fis ${srs_encode ...} to handle an empty sender address, now returning
an empty address. Previously the expansion returned an error.
+HS/01 Bug 2855: Handle a v4mapped sender address given us by a frontending
+ proxy. Previously these were misparsed, leading to paniclog entries.
+
Exim version 4.95
-----------------
*/
int
-host_address_extract_port(uschar *address)
+host_address_extract_port(uschar * address)
{
-int skip = -3; /* Skip 3 dots in IPv4 addresses */
-address--;
-while (*(++address) != 0)
+int port = 0;
+uschar *endptr;
+
+/* Handle the "bracketed with colon on the end" format */
+
+if (*address == '[')
+ {
+ uschar *rb = address + 1;
+ while (*rb != 0 && *rb != ']') rb++;
+ if (*rb++ == 0) return 0; /* Missing ]; leave invalid address */
+ if (*rb == ':')
+ {
+ port = Ustrtol(rb + 1, &endptr, 10);
+ if (*endptr != 0) return 0; /* Invalid port; leave invalid address */
+ }
+ else if (*rb != 0) return 0; /* Bad syntax; leave invalid address */
+ memmove(address, address + 1, rb - address - 2);
+ rb[-2] = 0;
+ }
+
+/* Handle the "dot on the end" format */
+
+else
{
- int ch = *address;
- if (ch == ':') skip = 0; /* Skip 0 dots in IPv6 addresses */
- else if (ch == '.' && skip++ >= 0) break;
+ int skip = -3; /* Skip 3 dots in IPv4 addresses */
+ address--;
+ while (*(++address) != 0)
+ {
+ int ch = *address;
+ if (ch == ':') skip = 0; /* Skip 0 dots in IPv6 addresses */
+ else if (ch == '.' && skip++ >= 0) break;
+ }
+ if (*address == 0) return 0;
+ port = Ustrtol(address + 1, &endptr, 10);
+ if (*endptr != 0) return 0; /* Invalid port; leave invalid address */
+ *address = 0;
}
-if (*address == 0) return 0;
-*address++ = 0;
-return Uatoi(address);
+
+return port;
}
* Extract port from address string *
*************************************************/
-/* In the spool file, and in the -oMa and -oMi options, a host plus port is
-given as an IP address followed by a dot and a port number. This function
-decodes this.
+/* In the -oMa and -oMi options, a host plus port is given as an IP address
+followed by a dot and a port number. This function decodes this.
An alternative format for the -oMa and -oMi options is [ip address]:port which
-is what Exim 4 uses for output, because it seems to becoming commonly used,
+is what Exim uses for output, because it seems to becoming commonly used,
whereas the dot form confuses some programs/people. So we recognize that form
too.
+The spool file used to use the first form, but this breaks with a v4mapped ipv6
+hybrid, because the parsing here is not clever. So for spool we now use the
+second form.
+
Argument:
address points to the string; if there is a port, the '.' in the string
is overwritten with zero to terminate the address; if the string
if (sender_host_address)
{
if (is_tainted(sender_host_address)) putc('-', fp);
- fprintf(fp, "-host_address %s.%d\n", sender_host_address, sender_host_port);
+ fprintf(fp, "-host_address [%s]:%d\n", sender_host_address, sender_host_port);
if (sender_host_name)
spool_var_write(fp, US"host_name", sender_host_name);
}
if (interface_address)
{
if (is_tainted(interface_address)) putc('-', fp);
- fprintf(fp, "-interface_address %s.%d\n", interface_address, interface_port);
+ fprintf(fp, "-interface_address [%s]:%d\n", interface_address, interface_port);
}
if (smtp_active_hostname != primary_hostname)
}
# Port in host address in spool file output from -Mvh
- s/^(--?host_address) (.*)\.\d+/$1 $2.9999/;
+ s/^(--?host_address) (.*[:.])\d+$/$1 ${2}9999/;
if ($dynamic_socket and $dynamic_socket->opened and my $port = $dynamic_socket->sockport) {
s/^Connecting to 127\.0\.0\.1 port \K$port/<dynamic port>/;
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
--interface_address 127.0.0.1.1225
+-host_address [127.0.0.1]:9999
+-interface_address [127.0.0.1]:1112
-received_protocol esmtp
-body_linecount 0
-max_received_linelength 0
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
--interface_address 127.0.0.1.1225
+-host_address [127.0.0.1]:9999
+-interface_address [127.0.0.1]:1112
-received_protocol esmtp
-body_linecount 0
-max_received_linelength 0
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
--interface_address 127.0.0.1.1225
+-host_address [127.0.0.1]:9999
+-interface_address [127.0.0.1]:1112
-received_protocol esmtp
-body_linecount 0
-max_received_linelength 0
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
--interface_address 127.0.0.1.1225
+-host_address [127.0.0.1]:9999
+-interface_address [127.0.0.1]:1112
-received_protocol esmtp
-body_linecount 0
-max_received_linelength 25
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
--interface_address 127.0.0.1.1225
+-host_address [127.0.0.1]:9999
+-interface_address [127.0.0.1]:1112
-received_protocol esmtp
-body_linecount 0
-max_received_linelength 25
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
--interface_address 127.0.0.1.1225
+-host_address [127.0.0.1]:9999
+-interface_address [127.0.0.1]:1112
-received_protocol esmtp
-body_linecount 0
-max_received_linelength 25
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
--interface_address 127.0.0.1.1225
+-host_address [127.0.0.1]:9999
+-interface_address [127.0.0.1]:1112
-received_protocol esmtp
-body_linecount 0
-max_received_linelength 25
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
+-host_address [127.0.0.1]:9999
-host_auth au1
-host_auth_pubname PLAIN
--interface_address 127.0.0.1.1225
+-interface_address [127.0.0.1]:1112
-received_protocol esmtpa
-body_linecount 0
-max_received_linelength 0
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
+-host_address [127.0.0.1]:9999
-host_auth au1
-host_auth_pubname PLAIN
--interface_address 127.0.0.1.1225
+-interface_address [127.0.0.1]:1112
-received_protocol esmtpa
-body_linecount 0
-max_received_linelength 0
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
+-host_address [127.0.0.1]:9999
-host_auth au1
-host_auth_pubname PLAIN
--interface_address 127.0.0.1.1225
+-interface_address [127.0.0.1]:1112
-received_protocol esmtpa
-body_linecount 0
-max_received_linelength 0
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
+-host_address [127.0.0.1]:9999
-host_auth au1
-host_auth_pubname PLAIN
--interface_address 127.0.0.1.1225
+-interface_address [127.0.0.1]:1112
-received_protocol esmtpa
-body_linecount 0
-max_received_linelength 0
-received_time_usec .uuuuuu
-received_time_complete tttt.uuuuuu
--helo_name rhu.barb
--host_address 127.0.0.1.9999
+-host_address [127.0.0.1]:9999
-host_auth au1
-host_auth_pubname PLAIN
--interface_address 127.0.0.1.1225
+-interface_address [127.0.0.1]:1112
-received_protocol esmtpa
-body_linecount 0
-max_received_linelength 15