From: Jeffrey Hutzelman Date: Sun, 22 Oct 2006 02:48:35 +0000 (+0000) Subject: kreltime-20061021 X-Git-Tag: BP-openafs-windows-kdfs-ifs~973 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=e720779b7c8472a0d928b0e1429b476f073309aa;p=packages%2Fo%2Fopenafs.git kreltime-20061021 FIXES 43551 kreltime-guard-against-null-tm-20060731 was apparently an attempt to deal with the possibility of localtime() returning NULL by using localtime_r instead, and zeroing the tm structure first. This has two problems. First, localtime_r is not guaranteed to leave its output buffer untouched or in a sane state in the event it is given invalid input. More importantly, the second half of this delta fixed the build on Windows (which apparently lacks localtime_r) at the expense of using the wrong level of indirection on other platforms. Simple is nice, but correct is important too. There is nothing wrong with switching to localtime_r to avoid thread safety issues. However, the correct fix for the anticipated problem was and is to check the return value of localtime (or localtime_r), and if it is NULL, fill in the ktime_date with suitable default values. The attached patch does not implement the correct fix, but does fix the double-indirection problem, so butc will again perform correctly instead of crashing. --- diff --git a/src/util/kreltime.c b/src/util/kreltime.c index 86f080aa4..1ed7e730d 100644 --- a/src/util/kreltime.c +++ b/src/util/kreltime.c @@ -121,8 +121,8 @@ ktimeDate_FromInt32(afs_int32 timeSecs, struct ktime_date *ktimePtr) timePtr = &timeP; - memset(&timePtr, 0, sizeof(timePtr)); - localtime_r(&tt, &timePtr); + memset(&timeP, 0, sizeof(timeP)); + localtime_r(&tt, &timeP); #else timePtr = localtime(&tt); #endif