Module Name: src Committed By: martin Date: Thu Jan 2 19:50:20 UTC 2025
Modified Files: src/bin/sh [netbsd-9]: var.c Log Message: Pull up following revision(s) (requested by kre in ticket #1932): bin/sh/var.c: revision 1.88 Fix a bug from when the ToD variable was added (July 2017) where if TZ is unset, and ToD_FORMAT contains and strftime() conversions which need to know the zone, bad things happen. Amazing that no-one (incl me) ever noticed this. To generate a diff of this commit: cvs rdiff -u -r1.78 -r1.78.2.1 src/bin/sh/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/var.c diff -u src/bin/sh/var.c:1.78 src/bin/sh/var.c:1.78.2.1 --- src/bin/sh/var.c:1.78 Thu Feb 14 11:15:24 2019 +++ src/bin/sh/var.c Thu Jan 2 19:50:20 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.78 2019/02/14 11:15:24 kre Exp $ */ +/* $NetBSD: var.c,v 1.78.2.1 2025/01/02 19:50:20 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: var.c,v 1.78 2019/02/14 11:15:24 kre Exp $"); +__RCSID("$NetBSD: var.c,v 1.78.2.1 2025/01/02 19:50:20 martin Exp $"); #endif #endif /* not lint */ @@ -1480,14 +1480,19 @@ get_tod(struct var *vp) len = vp->name_len + 4 + sizeof t_err - 1; continue; } - if (strftime_z(zone, buf.b + vp->name_len + 1, - buf.len - vp->name_len - 2, fmt, tmp)) { - if (zone && zone != last_zone) { - tzfree(zone); - INTON; + if (zone != NULL) { + if (strftime_z(zone, buf.b + vp->name_len + 1, + buf.len - vp->name_len - 2, fmt, tmp)) { + if (zone != last_zone) { + tzfree(zone); + INTON; + } + return buf.b; } - return buf.b; - } + } else if (strftime(buf.b + vp->name_len + 1, + buf.len - vp->name_len - 2, fmt, tmp)) + return buf.b; + if (len >= 4096) /* Let's be reasonable */ break; len <<= 1;