Module Name: src Committed By: kre Date: Thu Dec 26 03:23:28 UTC 2024
Modified Files: src/bin/sh: var.c Log Message: 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. XXX pullup -9, pullup -10 (and -8 from 8.0_RC1 onwards ... sigh) To generate a diff of this commit: cvs rdiff -u -r1.87 -r1.88 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.87 src/bin/sh/var.c:1.88 --- src/bin/sh/var.c:1.87 Mon Oct 21 15:56:44 2024 +++ src/bin/sh/var.c Thu Dec 26 03:23:28 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.87 2024/10/21 15:56:44 kre Exp $ */ +/* $NetBSD: var.c,v 1.88 2024/12/26 03:23:28 kre 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.87 2024/10/21 15:56:44 kre Exp $"); +__RCSID("$NetBSD: var.c,v 1.88 2024/12/26 03:23:28 kre Exp $"); #endif #endif /* not lint */ @@ -1551,14 +1551,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;