Module Name: src
Committed By: christos
Date: Wed Oct 27 11:27:26 UTC 2021
Modified Files:
src/lib/libc/time: localtime.c
Log Message:
fix problem with uninitialized variable on malformed 32 bit time.
To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/lib/libc/time/localtime.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/time/localtime.c
diff -u src/lib/libc/time/localtime.c:1.124 src/lib/libc/time/localtime.c:1.125
--- src/lib/libc/time/localtime.c:1.124 Fri Oct 22 10:26:04 2021
+++ src/lib/libc/time/localtime.c Wed Oct 27 07:27:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: localtime.c,v 1.124 2021/10/22 14:26:04 christos Exp $ */
+/* $NetBSD: localtime.c,v 1.125 2021/10/27 11:27:25 christos Exp $ */
/* Convert timestamp from time_t to struct tm. */
@@ -12,7 +12,7 @@
#if 0
static char elsieid[] = "@(#)localtime.c 8.17";
#else
-__RCSID("$NetBSD: localtime.c,v 1.124 2021/10/22 14:26:04 christos Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.125 2021/10/27 11:27:25 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -583,26 +583,27 @@ tzloadbody(char const *name, struct stat
detzcode64(p);
int_fast32_t corr = detzcode(p + stored);
p += stored + 4;
+
/* Leap seconds cannot occur before the Epoch,
or out of order. */
if (tr <= prevtr)
return EINVAL;
- if (tr <= TIME_T_MAX) {
- /* To avoid other botches in this code, each leap second's
- correction must differ from the previous one's by 1
- second or less, except that the first correction can be
- any value; these requirements are more generous than
- RFC 8536, to allow future RFC extensions. */
+ /* To avoid other botches in this code, each leap second's
+ correction must differ from the previous one's by 1
+ second or less, except that the first correction can be
+ any value; these requirements are more generous than
+ RFC 8536, to allow future RFC extensions. */
if (! (i == 0
|| (prevcorr < corr
? corr == prevcorr + 1
: (corr == prevcorr
|| corr == prevcorr - 1))))
- return EINVAL;
-
- sp->lsis[leapcnt].ls_trans =
- (time_t)(prevtr = tr);
- sp->lsis[leapcnt].ls_corr = prevcorr = corr;
+ return EINVAL;
+ prevtr = tr;
+ prevcorr = corr;
+ if (tr <= TIME_T_MAX) {
+ sp->lsis[leapcnt].ls_trans = (time_t)tr;
+ sp->lsis[leapcnt].ls_corr = corr;
leapcnt++;
}
}