[core] fix 1.4.46 regression in config match (fixes #2830)

address strings need to have DNS resolved and port added
for consistency when matching other config conditionals

x-ref:
  "1.4.46 regression: $SERVER["socket"] matches when it shouldn't"
  https://redmine.lighttpd.net/issues/2830
This commit is contained in:
Glenn Strauss 2017-10-22 12:24:18 -04:00
parent 60b5826849
commit 585206616d
1 changed files with 8 additions and 1 deletions

View File

@ -205,7 +205,14 @@ static int network_server_init(server *srv, buffer *host_token, size_t sidx, int
srv_socket->is_ssl = s->ssl_enabled;
srv_socket->srv_token = buffer_init();
sock_addr_inet_ntop_copy_buffer(srv_socket->srv_token, &srv_socket->addr);
if (addr.plain.sa_family == AF_INET6) buffer_append_string_len(srv_socket->srv_token, CONST_STR_LEN("["));
sock_addr_inet_ntop_append_buffer(srv_socket->srv_token, &srv_socket->addr);
if (addr.plain.sa_family == AF_INET6) buffer_append_string_len(srv_socket->srv_token, CONST_STR_LEN("]"));
if (addr.plain.sa_family != AF_UNIX) {
port = addr.plain.sa_family == AF_INET ? ntohs(addr.ipv4.sin_port) : ntohs(addr.ipv6.sin6_port);
buffer_append_string_len(srv_socket->srv_token, CONST_STR_LEN(":"));
buffer_append_int(srv_socket->srv_token, (int)port);
}
/* update host_token (dc->string) for consistent string comparison in lighttpd.conf conditions */
buffer_copy_buffer(host_token, srv_socket->srv_token);