Re: httpd: remove redundant search and check return value

Kirill A. Korinsky <[email protected]> Fri, 17 Jul 2026 15:26:21 +0200
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
On Tue, 14 Jul 2026 08:07:32 +0200,
Rafael Sadowski <[email protected]> wrote:
> 
> OK?
>

Trivial and sane, OK kirill@

> commit 314f1d8872647165256696609b5a6b03878d1100
> Author: Rafael Sadowski <[email protected]>
> Date:   Tue Jul 14 07:56:55 2026 +0200
> 
>     httpd: remove redundant search and check return value
>     
>     The server foreach-loop serves the same purpose as "serverconfig_byid"
>     did previously.
> 
> diff --git a/config.c b/config.c
> index c2062a3..9ba772b 100644
> --- a/config.c
> +++ b/config.c
> @@ -352,8 +352,7 @@ config_settls(struct httpd *env, struct server *srv, enum tls_config_type type,
>  int
>  config_getserver_fcgiparams(struct httpd *env, struct imsg *imsg)
>  {
> -	struct server		*srv;
> -	struct server_config	*srv_conf, *iconf;
> +	struct server_config	*srv_conf;
>  	struct fastcgi_param	*fp;
>  	uint32_t		 id;
>  	size_t			 c, nc, len;
> @@ -369,29 +368,19 @@ config_getserver_fcgiparams(struct httpd *env, struct imsg *imsg)
>  	p += sizeof(nc);
>  
>  	memcpy(&id, p, sizeof(id));	/* server conf id */
> -	srv_conf = serverconfig_byid(id);
>  	p += sizeof(id);
>  
> +	if ((srv_conf = serverconfig_byid(id)) == NULL) {
> +		log_debug("%s: server not found", __func__);
> +		return(-1);
> +	}
> +
>  	len += nc*sizeof(*fp);
>  	if (IMSG_DATA_SIZE(imsg) < len) {
>  		log_debug("%s: invalid message length", __func__);
>  		return (-1);
>  	}
>  
> -	/* Find associated server config */
> -	TAILQ_FOREACH(srv, env->sc_servers, srv_entry) {
> -		if (srv->srv_conf.id == id) {
> -			srv_conf = &srv->srv_conf;
> -			break;
> -		}
> -		TAILQ_FOREACH(iconf, &srv->srv_hosts, entry) {
> -			if (iconf->id == id) {
> -				srv_conf = iconf;
> -				break;
> -			}
> -		}
> -	}
> -
>  	/* Fetch FCGI parameters */
>  	for (c = 0; c < nc; c++) {
>  		if ((fp = calloc(1, sizeof(*fp))) == NULL)
> 

-- 
wbr, Kirill