Index | Thread | Search

From:
"Theo de Raadt" <deraadt@openbsd.org>
Subject:
Re: Document timegm() error return
To:
Theo Buehler <tb@theobuehler.org>
Cc:
tech@openbsd.org
Date:
Sun, 12 Apr 2026 22:17:38 -0600

Download raw body.

Thread
I kind of like this imprecise description of the problem because it
will raise eyebrows and probably increase caution.

> The RETURN VALUE of timegm() is undocumented.
> 
> mktime() and timegm() call time1(), which returns WRONG aka -1 on error.
> Of course, struct tm can represent Dec 31, 1969, 23:59:59, so this is
> not necessarily an error. Wording adapted from ASN1_INTEGER_get(), which
> suffers from the same fundamental design flaw.
> 
> It may well deserve more calling out, e.g., in DESCRIPTION and CAVEATS.
> I'll leave that for someone else to fix.
> 
> Index: time/ctime.3
> ===================================================================
> RCS file: /cvs/src/lib/libc/time/ctime.3,v
> diff -u -p -r1.50 ctime.3
> --- time/ctime.3	20 Nov 2025 10:58:11 -0000	1.50
> +++ time/ctime.3	13 Apr 2026 03:46:41 -0000
> @@ -278,9 +278,12 @@ The functions
>  and
>  .Fn gmtime_r
>  return NULL on error.
> -The function
> +The functions
>  .Fn mktime
> -returns \-1 on error.
> +and
> +.Fn gmtime
> +return \-1 on error,
> +which is ambiguous because \-1 is a legitimate conversion result.
>  .Sh FILES
>  .Bl -tag -width "/usr/share/zoneinfo/posixrules" -compact
>  .It Pa /usr/share/zoneinfo
>