From 9bdc24477505bf2c93f1ecb021cd648693b21ef3 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 14 Jul 2026 23:42:15 +0200 Subject: [PATCH 1/8] lib/tz.c, etc/, man/, tests/: Default to TZ=UTC CST6CDT seems to be a deprecated name, and also it feels weird to have an offset by default. The world defaults to UTC these days for most stuff. Signed-off-by: Alejandro Colomar --- etc/login.defs | 2 +- lib/tz.c | 2 +- man/login.defs.d/ENV_TZ.xml | 4 ++-- tests/newusers/62_create_user_no_aging/config/etc/login.defs | 2 +- tests/system/etc/login.defs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/etc/login.defs b/etc/login.defs index 1b81afd82e..c05bb3ba59 100644 --- a/etc/login.defs +++ b/etc/login.defs @@ -143,7 +143,7 @@ HUSHLOGIN_FILE .hushlogin # If defined, either a TZ environment parameter spec or the # fully-rooted pathname of a file containing such a spec. # -#ENV_TZ TZ=CST6CDT +#ENV_TZ TZ=UTC #ENV_TZ /etc/tzname # diff --git a/lib/tz.c b/lib/tz.c index b2d9531e20..afcb952373 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -39,7 +39,7 @@ fp = fopen (fname, "r"); if ( (NULL == fp) || (fgets_a(tzbuf, fp) == NULL)) { - result = "TZ=CST6CDT"; + result = "TZ=UTC"; } else { stpsep(tzbuf, "\n"); result = tzbuf; diff --git a/man/login.defs.d/ENV_TZ.xml b/man/login.defs.d/ENV_TZ.xml index 04d208ed05..bef702f58e 100644 --- a/man/login.defs.d/ENV_TZ.xml +++ b/man/login.defs.d/ENV_TZ.xml @@ -11,14 +11,14 @@ If set, it will be used to define the TZ environment variable when a user login. The value can be the name of a timezone preceded by TZ= (for example - TZ=CST6CDT), or the full path to the file + TZ=UTC), or the full path to the file containing the timezone specification (for example /etc/tzname). If a full path is specified but the file does not exist or cannot be - read, the default is to use TZ=CST6CDT. + read, the default is to use TZ=UTC. diff --git a/tests/newusers/62_create_user_no_aging/config/etc/login.defs b/tests/newusers/62_create_user_no_aging/config/etc/login.defs index 1e61b5cd41..8beb789ee3 100644 --- a/tests/newusers/62_create_user_no_aging/config/etc/login.defs +++ b/tests/newusers/62_create_user_no_aging/config/etc/login.defs @@ -143,7 +143,7 @@ HUSHLOGIN_FILE .hushlogin # If defined, either a TZ environment parameter spec or the # fully-rooted pathname of a file containing such a spec. # -#ENV_TZ TZ=CST6CDT +#ENV_TZ TZ=UTC #ENV_TZ /etc/tzname # diff --git a/tests/system/etc/login.defs b/tests/system/etc/login.defs index 7f1feffd64..2286c0b85b 100644 --- a/tests/system/etc/login.defs +++ b/tests/system/etc/login.defs @@ -143,7 +143,7 @@ HUSHLOGIN_FILE .hushlogin # If defined, either a TZ environment parameter spec or the # fully-rooted pathname of a file containing such a spec. # -#ENV_TZ TZ=CST6CDT +#ENV_TZ TZ=UTC #ENV_TZ /etc/tzname # From 67d85220165b5ea74bdd733757d014dac35d2efb Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 14 Jul 2026 23:50:11 +0200 Subject: [PATCH 2/8] lib/tz.c: tz(): Remove unused initialization We set 'fp' unconditionally with the result of fopen(3). Signed-off-by: Alejandro Colomar --- lib/tz.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tz.c b/lib/tz.c index afcb952373..2bc5eca408 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -32,7 +32,7 @@ */ /*@observer@*/const char *tz (const char *fname) { - FILE *fp = NULL; + FILE *fp; const char *result; static char tzbuf[BUFSIZ]; From 2c626466b45c30a0fcbad65ab5069fe02fd55ce1 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 14 Jul 2026 23:47:07 +0200 Subject: [PATCH 3/8] lib/tz.c: tz(): Return early on error, to simplify Signed-off-by: Alejandro Colomar --- lib/tz.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/tz.c b/lib/tz.c index 2bc5eca408..13f352d1ee 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -37,18 +37,17 @@ static char tzbuf[BUFSIZ]; fp = fopen (fname, "r"); - if ( (NULL == fp) - || (fgets_a(tzbuf, fp) == NULL)) { + if (fp == NULL) + return "TZ=UTC"; + + if (fgets_a(tzbuf, fp) == NULL) { result = "TZ=UTC"; } else { stpsep(tzbuf, "\n"); result = tzbuf; } - if (NULL != fp) { - (void) fclose (fp); - } - + fclose(fp); return result; } #else /* !USE_PAM */ From 274dcd2858603565802df7ffcec4df47ef7c7f64 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 14 Jul 2026 23:51:24 +0200 Subject: [PATCH 4/8] lib/tz.c: tz(): Use goto to 'hide' error handling Signed-off-by: Alejandro Colomar --- lib/tz.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/tz.c b/lib/tz.c index 13f352d1ee..ac62955a18 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -33,22 +33,22 @@ /*@observer@*/const char *tz (const char *fname) { FILE *fp; - const char *result; static char tzbuf[BUFSIZ]; fp = fopen (fname, "r"); if (fp == NULL) return "TZ=UTC"; - if (fgets_a(tzbuf, fp) == NULL) { - result = "TZ=UTC"; - } else { - stpsep(tzbuf, "\n"); - result = tzbuf; - } + if (fgets_a(tzbuf, fp) == NULL) + goto def; + stpsep(tzbuf, "\n"); + + fclose(fp); + return tzbuf; +def: fclose(fp); - return result; + return "TZ=UTC"; } #else /* !USE_PAM */ extern int ISO_C_forbids_an_empty_translation_unit; From c749d8029debfa131129c3dfe41e35d02d39236d Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 14 Jul 2026 23:59:02 +0200 Subject: [PATCH 5/8] lib/tz.c: tz(): Fail for non-text files Signed-off-by: Alejandro Colomar --- lib/tz.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tz.c b/lib/tz.c index ac62955a18..0e4bb9835d 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -41,8 +41,8 @@ if (fgets_a(tzbuf, fp) == NULL) goto def; - - stpsep(tzbuf, "\n"); + if (stpsep(tzbuf, "\n") == NULL) + goto def; fclose(fp); return tzbuf; From 8ad129a78dcc707bf51c9b26179069b2093c9ed5 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 15 Jul 2026 00:03:26 +0200 Subject: [PATCH 6/8] lib/tz.c: tz(): Rename local variables 'buf' instead of 'tzbuf', since it's a more common name. 'fname' => 'path', since it represents a path name, and not just a file component. Signed-off-by: Alejandro Colomar --- lib/tz.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/tz.c b/lib/tz.c index 0e4bb9835d..c090605ac2 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -1,19 +1,16 @@ -/* - * SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1991 - 1994, Chip Rosenthal - * SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2007 - 2010, Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ +// SPDX-FileCopyrightText: 1991-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1991-1994, Chip Rosenthal +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2007-2010, Nicolas François +// SPDX-FileCopyrightText: 2026, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + #include "config.h" #ifndef USE_PAM -#ident "$Id$" - #include #include @@ -28,24 +25,26 @@ * tz - return local timezone name * * tz() determines the name of the local timezone by reading the - * contents of the file named by ``fname''. + * contents of the file named by 'path'. */ -/*@observer@*/const char *tz (const char *fname) +/*@observer@*/ +const char * +tz(const char *path) { FILE *fp; - static char tzbuf[BUFSIZ]; + static char buf[BUFSIZ]; - fp = fopen (fname, "r"); + fp = fopen(path, "r"); if (fp == NULL) return "TZ=UTC"; - if (fgets_a(tzbuf, fp) == NULL) + if (fgets_a(buf, fp) == NULL) goto def; - if (stpsep(tzbuf, "\n") == NULL) + if (stpsep(buf, "\n") == NULL) goto def; fclose(fp); - return tzbuf; + return buf; def: fclose(fp); return "TZ=UTC"; @@ -53,4 +52,3 @@ #else /* !USE_PAM */ extern int ISO_C_forbids_an_empty_translation_unit; #endif /* !USE_PAM */ - From 9091ca85d7fad9fbcb425b32c82852d4d4afd394 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 15 Jul 2026 00:17:32 +0200 Subject: [PATCH 7/8] lib/tz.c: tz(): Use a more appropriate buffer size While at it, remove unused includes. Signed-off-by: Alejandro Colomar --- lib/tz.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/tz.c b/lib/tz.c index c090605ac2..61077dbbd3 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -11,11 +11,9 @@ #ifndef USE_PAM +#include #include -#include -#include "defines.h" -#include "getdef.h" #include "io/fgets/fgets.h" #include "prototypes.h" #include "string/strtok/stpsep.h" @@ -32,7 +30,7 @@ const char * tz(const char *path) { FILE *fp; - static char buf[BUFSIZ]; + static char buf[LINE_MAX + 1]; fp = fopen(path, "r"); if (fp == NULL) From 6b884cb2be399237c46dd506f0f29f8b6cea4d8f Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 15 Jul 2026 00:31:04 +0200 Subject: [PATCH 8/8] lib/tz.c: DEFAULT_TZ: Add macro to centralize "TZ=UTC" Signed-off-by: Alejandro Colomar --- lib/tz.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tz.c b/lib/tz.c index 61077dbbd3..bbcddb4253 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -19,6 +19,9 @@ #include "string/strtok/stpsep.h" +#define DEFAULT_TZ "TZ=UTC" + + /* * tz - return local timezone name * @@ -34,7 +37,7 @@ tz(const char *path) fp = fopen(path, "r"); if (fp == NULL) - return "TZ=UTC"; + return DEFAULT_TZ; if (fgets_a(buf, fp) == NULL) goto def; @@ -45,7 +48,7 @@ tz(const char *path) return buf; def: fclose(fp); - return "TZ=UTC"; + return DEFAULT_TZ; } #else /* !USE_PAM */ extern int ISO_C_forbids_an_empty_translation_unit;