Re: ntpd timegm error checks

Job Snijders <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
OK

On Sun, May 31, 2026 at 12:23:26PM +0200, Theo Buehler wrote:
> Another rather straightforward conversion, removing a confusing comment
> that would become a bit more confusing.
> 
> As visible in the diff, tls_tm is parsed twice in a row, where the
> second (rather the first) parse was added with the manual constraints
> checking in 2019. The layering is a bit strange here.
> 
> Index: constraint.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ntpd/constraint.c,v
> diff -u -p -r1.60 constraint.c
> --- constraint.c	21 Nov 2024 13:38:14 -0000	1.60
> +++ constraint.c	31 May 2026 10:14:09 -0000
> @@ -1062,7 +1062,9 @@ httpsdate_request(struct httpsdate *http
>  	 */
>  	notbefore = tls_peer_cert_notbefore(httpsdate->tls_ctx);
>  	notafter = tls_peer_cert_notafter(httpsdate->tls_ctx);
> -	if ((httptime = timegm(&httpsdate->tls_tm)) == -1)
> +	httpsdate->tls_tm.tm_wday = -1;
> +	if ((httptime = timegm(&httpsdate->tls_tm)) == -1 &&
> +	    httpsdate->tls_tm.tm_wday == -1)
>  		goto fail;
>  	if (httptime <= notbefore) {
>  		if ((tm = gmtime(&notbefore)) == NULL)
> @@ -1114,8 +1116,12 @@ httpsdate_query(const char *addr, const 
>  	if (httpsdate_request(httpsdate, &when, synced) == -1)
>  		return (NULL);
>  
> -	/* Return parsed date as local time */
> +	httpsdate->tls_tm.tm_wday = -1;
>  	t = timegm(&httpsdate->tls_tm);
> +	if (t == -1 && httpsdate->tls_tm.tm_wday == -1) {
> +		httpsdate_free(httpsdate);
> +		return (NULL);
> +	}
>  
>  	/* Report parsed Date: as "received time" */
>  	rectv->tv_sec = t;
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.