From: Christopher Faulet Date: Tue, 28 Apr 2020 08:31:53 +0000 (+0200) Subject: MINOR: checks: Make the use of the check's server more explicit on connect X-Git-Tag: v2.2-dev7~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=931ae5b1034fb61d989e5365aa4ba97f74b8c865;p=thirdparty%2Fhaproxy.git MINOR: checks: Make the use of the check's server more explicit on connect The variable s, pointing on the check server, may be null when a connection is openned. It happens for email alerts. To avoid ambiguities, its use is now more explicit. Comments have been added at some places and tests on the variable have been added elsewhere (useless but explicit). Partly fixes issue #600. --- diff --git a/src/checks.c b/src/checks.c index c79cc1fdd8..2b60fbce21 100644 --- a/src/checks.c +++ b/src/checks.c @@ -1683,7 +1683,8 @@ static enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct } /* connect to the connect rule addr if specified, otherwise the check - * addr if specified on the server. otherwise, use the server addr + * addr if specified on the server. otherwise, use the server addr (it + * MUST exist at this step). */ *conn->dst = (is_addr(&connect->addr) ? connect->addr @@ -1708,8 +1709,10 @@ static enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct port = check->port; if (!port && is_inet_addr(&check->addr)) port = get_host_port(&check->addr); - if (!port) + if (!port) { + /* The server MUST exist here */ port = s->svc_port; + } set_host_port(conn->dst, port); xprt = ((connect->options & TCPCHK_OPT_SSL) @@ -1767,19 +1770,19 @@ static enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct #ifdef USE_OPENSSL if (connect->sni) ssl_sock_set_servername(conn, connect->sni); - else if ((connect->options & TCPCHK_OPT_DEFAULT_CONNECT) && s->check.sni) + else if ((connect->options & TCPCHK_OPT_DEFAULT_CONNECT) && s && s->check.sni) ssl_sock_set_servername(conn, s->check.sni); if (connect->alpn) ssl_sock_set_alpn(conn, (unsigned char *)connect->alpn, connect->alpn_len); - else if ((connect->options & TCPCHK_OPT_DEFAULT_CONNECT) && s->check.alpn_str) + else if ((connect->options & TCPCHK_OPT_DEFAULT_CONNECT) && s && s->check.alpn_str) ssl_sock_set_alpn(conn, (unsigned char *)s->check.alpn_str, s->check.alpn_len); #endif - if ((connect->options & TCPCHK_OPT_SOCKS4) && (s->flags & SRV_F_SOCKS4_PROXY)) { + if ((connect->options & TCPCHK_OPT_SOCKS4) && s && (s->flags & SRV_F_SOCKS4_PROXY)) { conn->send_proxy_ofs = 1; conn->flags |= CO_FL_SOCKS4; } - else if ((connect->options & TCPCHK_OPT_DEFAULT_CONNECT) && s->check.via_socks4 && (s->flags & SRV_F_SOCKS4_PROXY)) { + else if ((connect->options & TCPCHK_OPT_DEFAULT_CONNECT) && s && s->check.via_socks4 && (s->flags & SRV_F_SOCKS4_PROXY)) { conn->send_proxy_ofs = 1; conn->flags |= CO_FL_SOCKS4; } @@ -1788,7 +1791,7 @@ static enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct conn->send_proxy_ofs = 1; conn->flags |= CO_FL_SEND_PROXY; } - else if ((connect->options & TCPCHK_OPT_DEFAULT_CONNECT) && s->check.send_proxy && !(check->state & CHK_ST_AGENT)) { + else if ((connect->options & TCPCHK_OPT_DEFAULT_CONNECT) && s && s->check.send_proxy && !(check->state & CHK_ST_AGENT)) { conn->send_proxy_ofs = 1; conn->flags |= CO_FL_SEND_PROXY; }