Skip to content

Commit ccb9728

Browse files
krekre
kre
authored and
kre
committed
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)
1 parent c0558ef commit ccb9728

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

bin/sh/var.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: var.c,v 1.87 2024/10/21 15:56:44 kre Exp $ */
1+
/* $NetBSD: var.c,v 1.88 2024/12/26 03:23:28 kre Exp $ */
22

33
/*-
44
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
3737
#if 0
3838
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95";
3939
#else
40-
__RCSID("$NetBSD: var.c,v 1.87 2024/10/21 15:56:44 kre Exp $");
40+
__RCSID("$NetBSD: var.c,v 1.88 2024/12/26 03:23:28 kre Exp $");
4141
#endif
4242
#endif /* not lint */
4343

@@ -1551,14 +1551,19 @@ get_tod(struct var *vp)
15511551
len = vp->name_len + 4 + sizeof t_err - 1;
15521552
continue;
15531553
}
1554-
if (strftime_z(zone, buf.b + vp->name_len + 1,
1555-
buf.len - vp->name_len - 2, fmt, tmp)) {
1556-
if (zone && zone != last_zone) {
1557-
tzfree(zone);
1558-
INTON;
1554+
if (zone != NULL) {
1555+
if (strftime_z(zone, buf.b + vp->name_len + 1,
1556+
buf.len - vp->name_len - 2, fmt, tmp)) {
1557+
if (zone != last_zone) {
1558+
tzfree(zone);
1559+
INTON;
1560+
}
1561+
return buf.b;
15591562
}
1560-
return buf.b;
1561-
}
1563+
} else if (strftime(buf.b + vp->name_len + 1,
1564+
buf.len - vp->name_len - 2, fmt, tmp))
1565+
return buf.b;
1566+
15621567
if (len >= 4096) /* Let's be reasonable */
15631568
break;
15641569
len <<= 1;

0 commit comments

Comments
 (0)