NetBSD Problem Report #60219
From wiz@netbsd.org Thu Apr 30 19:30:57 2026
Return-Path: <wiz@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
client-signature RSA-PSS (2048 bits) client-digest SHA256)
(Client CN "mail.netbsd.org", Issuer "R12" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id E90D01A9239
for <gnats-bugs@gnats.NetBSD.org>; Thu, 30 Apr 2026 19:30:56 +0000 (UTC)
Message-Id: <20260430193056.7376084D27@mail.netbsd.org>
Date: Thu, 30 Apr 2026 19:30:56 +0000 (UTC)
From: wiz@NetBSD.org
Reply-To: wiz@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: sysconf overpromises TZNAME_MAX
X-Send-Pr-Version: 3.95
X-From4GNATS: "wiz@NetBSD.org via gnats" <gnats-admin@NetBSD.org>
>Number: 60219
>Category: lib
>Synopsis: sysconf overpromises TZNAME_MAX
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kre
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Apr 30 19:35:00 +0000 2026
>Closed-Date: Thu May 07 18:25:29 +0000 2026
>Last-Modified: Thu May 07 18:25:29 +0000 2026
>Originator: Thomas Klausner
>Release: NetBSD 11.99.5
>Organization:
>Environment:
11.99.5/20260408 and 11.0_RC3
Architecture: x86_64
Machine: amd64
>Description:
When running the gnulib tests for parse-datetime, there is a test failure.
The problem is that the code wants to test extreme cases, so it generates
a time zone string of maximum allowed length and expects that libc will parse
it, but instead it is refused as too long.
Bruno Haible investigated and found that even though sysconf(3) returns
511 for sysconf (_SC_TZNAME_MAX), which is also what I see on my system:
# getconf TZNAME_MAX
511
libc seems to have a limit of 254 instead.
I guess, but haven't verified, that this is from src/lib/libc/time/localtime.c
#ifndef TZNAME_MAXIMUM
# define TZNAME_MAXIMUM 254
#endif
I'm not sure where the 511 for _SC_TZNAME_MAX comes from; however, while
looking for this I found in lib/libc/gen/sysctl.c:
_INT("tzname_max", USER_TZNAME_MAX, NAME_MAX,
"The minimum maximum number of types supported for the "
"name of a timezone"),
where I think 'types' should be replaced by 'characters'.
>How-To-Repeat:
$ git clone --depth=1 https://git.savannah.gnu.org/git/gnulib.git
$ cd gnulib
$ ./gnulib-tool --create-testdir --dir t parse-datetime
$ cd t
$ ./configure && make && make check
>Fix:
Adapt the real limit to the reported limited, or the other way round.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: lib-bug-people->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Fri, 01 May 2026 04:36:04 +0000
Responsible-Changed-Why:
I am looking into this PR
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: lib/60219: sysconf overpromises TZNAME_MAX
Date: Fri, 01 May 2026 12:19:08 +0700
Date: Thu, 30 Apr 2026 19:35:00 +0000 (UTC)
From: "wiz@NetBSD.org via gnats" <gnats-admin@NetBSD.org>
Message-ID: <20260430193500.7870C1A9241@mollari.NetBSD.org>
| Bruno Haible investigated and found that even though sysconf(3) returns
| 511 for sysconf (_SC_TZNAME_MAX), which is also what I see on my system:
|
| # getconf TZNAME_MAX
| 511
|
| libc seems to have a limit of 254 instead.
Yes, that is clearly broken, sysconf(_SC_TZNAME_MAX) is supposed to
return the minimum value that TZNAME_MAX can be - the POSIX default for that
is 6 (which is perhaps a bit short, but these are the abbreviations
("EST" etc) and don't need to be all that long). The current tzcode
max length is 254 (way more than 6) - chosen so the length of the abbrev
will fit in one byte.
Returning NAME_MAX (which has nothing whatever to do with the issue)
which is what we were doing is nonsense, it is more than libc (and hence
zic) allows, when it is supposed to be less (or equal). It is almost
as if the proverbial someone believed that TZNAME_MAX has something to
do with the file name (America/New_York) - for which NAME_MAX might be
appropriate.
There are two possible solutions, one is to treat sysconf(_SC_TZNAME_MAX)
as it is defined, and make it the min value we'd ever support (say 31 or
something like that) even though we actually support lots more than that
(254), or we set it to be the value we actually support, rather than being
the minimum allowed value.
In some ways I prefer the former, it means the value will never need to
change in the future (unless something very weird happens), whereas setting
it to the actual supported value means every new tzcode release might alter
what it gets set to (tzcode changed it from 255 to 254 not all that long
ago, so the (unsigned)"-1" byte value could be used for other purposes).
For now I am going to do the latter however, as that seems more consistent
with how we typically set these "minimum allowed" sysconf values - making
them represent what we currently allow, which is clearly both the minimum
max value, and the max max value (for now).
| I'm not sure where the 511 for _SC_TZNAME_MAX comes from;
libc/gen/sysctl.c - the user.whatever sysctl() values are all embedded
in there. (sysconf() uses sysctl() to get the value - no actual system
call is required for it).
| where I think 'types' should be replaced by 'characters'.
That typo exists in several places, I found several, but no idea if
I got all that exist.
kre
State-Changed-From-To: open->analyzed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Fri, 01 May 2026 05:43:52 +0000
State-Changed-Why:
Issue understood, fix coming (undergoing testing)
From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/60219 CVS commit: src
Date: Fri, 1 May 2026 07:19:46 +0000
Module Name: src
Committed By: kre
Date: Fri May 1 07:19:45 UTC 2026
Modified Files:
src/include: time.h
src/lib/libc/gen: sysconf.3 sysctl.c
src/lib/libc/time: localtime.c
src/share/man/man7: sysctl.7
Log Message:
PR lib/60219 -- Fix sysconf(_SC_TZNAME_MAX)
That value is supposed to be the minimum value allowed for
the maximum length of a timezone abbreviation. It cannot
be something larger than is allowed for that (and NAME_MAX
has nothing to do with it)
It defines the max lengths allowed for the words in
TZ=Frankenstein-7Monster-6[transition rules]
in old style POSIX TZ variable settings - the POSIX required
minimum value is 6 (so "Frankenstein" would not fit in a minimalist
POSIX implementation).
For now, sync the values between libc/sysctl() and libc/localtime()
via a new _TZNAME_MAXIMUM definition in <time.h> and use that for
both purposes (as a possible default anyway for localtime() - there
the default value used will always be at least 254, and building with
-DTZNAME_MAXIMUM=N can override that value with anything larger than
_TZNAME_MAXIMUM if desired).
While here fix as many instances of the "max number of types" (which
should be "max number of bytes") string in related contexts that I could
find - there might perhaps be more.
XXX pullup -11 (at least)
To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/include/time.h
cvs rdiff -u -r1.57 -r1.58 src/lib/libc/gen/sysconf.3
cvs rdiff -u -r1.39 -r1.40 src/lib/libc/gen/sysctl.c
cvs rdiff -u -r1.153 -r1.154 src/lib/libc/time/localtime.c
cvs rdiff -u -r1.171 -r1.172 src/share/man/man7/sysctl.7
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: analyzed->needs-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Fri, 01 May 2026 07:23:05 +0000
State-Changed-Why:
Needs a pullup to -11, this one probably isn't worth fixing in older releases.
From: Thomas Klausner <wiz@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: kre@netbsd.org
Subject: Re: lib/60219: sysconf overpromises TZNAME_MAX
Date: Fri, 1 May 2026 12:57:20 +0200
Thanks, Robert, for fixing this.
I can confirm that the test now completes successfully.
Thomas
State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Fri, 01 May 2026 12:06:59 +0000
State-Changed-Why:
[pullup-11 #267]
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/60219 CVS commit: [netbsd-11] src
Date: Thu, 7 May 2026 15:43:06 +0000
Module Name: src
Committed By: martin
Date: Thu May 7 15:43:06 UTC 2026
Modified Files:
src/include [netbsd-11]: time.h
src/lib/libc/gen [netbsd-11]: sysconf.3 sysctl.c
src/lib/libc/time [netbsd-11]: localtime.c
src/share/man/man7 [netbsd-11]: sysctl.7
Log Message:
Pull up following revision(s) (requested by kre in ticket #267):
lib/libc/gen/sysctl.c: revision 1.40
lib/libc/gen/sysconf.3: revision 1.58
share/man/man7/sysctl.7: revision 1.172
lib/libc/time/localtime.c: revision 1.154
include/time.h: revision 1.57
PR lib/60219 -- Fix sysconf(_SC_TZNAME_MAX)
That value is supposed to be the minimum value allowed for
the maximum length of a timezone abbreviation. It cannot
be something larger than is allowed for that (and NAME_MAX
has nothing to do with it)
It defines the max lengths allowed for the words in
TZ=Frankenstein-7Monster-6[transition rules]
in old style POSIX TZ variable settings - the POSIX required
minimum value is 6 (so "Frankenstein" would not fit in a minimalist
POSIX implementation).
For now, sync the values between libc/sysctl() and libc/localtime()
via a new _TZNAME_MAXIMUM definition in <time.h> and use that for
both purposes (as a possible default anyway for localtime() - there
the default value used will always be at least 254, and building with
- -DTZNAME_MAXIMUM=N can override that value with anything larger than
_TZNAME_MAXIMUM if desired).
While here fix as many instances of the "max number of types" (which
should be "max number of bytes") string in related contexts that I could
find - there might perhaps be more.
To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.56.2.1 src/include/time.h
cvs rdiff -u -r1.57 -r1.57.4.1 src/lib/libc/gen/sysconf.3
cvs rdiff -u -r1.38.10.1 -r1.38.10.2 src/lib/libc/gen/sysctl.c
cvs rdiff -u -r1.147 -r1.147.2.1 src/lib/libc/time/localtime.c
cvs rdiff -u -r1.167.4.1 -r1.167.4.2 src/share/man/man7/sysctl.7
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: pending-pullups->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Thu, 07 May 2026 18:25:29 +0000
State-Changed-Why:
Pullups completed
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.