summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2017-03-01 01:45:52 +0000
committeremaste <emaste@FreeBSD.org>2017-03-01 01:45:52 +0000
commitab3ab7c73bbcf54890a5e036d2d843414fb25b24 (patch)
tree1c873d0337de30c2039526cc7be485f503cf6549
parent4e0496e11c82512bca4f5dd7efe6474ed1b7e93b (diff)
downloadFreeBSD-src-ab3ab7c73bbcf54890a5e036d2d843414fb25b24.zip
FreeBSD-src-ab3ab7c73bbcf54890a5e036d2d843414fb25b24.tar.gz
MFC r313774: localtime: return NULL if time_t out of range of struct tm
Previously we would truncate tm.tm_year for any time_t corresponding to a year that does not fit in int. This issue was discovered because it caused the bash-static build to fail when linking with LLD. As reported by Rafael EspĂ­ndola: Configure has AC_FUNC_MKTIME which expands to a test of mktime that fails with the freebsd implementation. Given that, bash compiles a mktime.o file that defines just mktime and uses localtime. That goes in a .a file that is before libc. The freebsd libc defines mktime in localtime.o, which also defines localtime among other functions. When lld sees an undefined reference to mktime from libc, it uses the bash provided one and then tries to find a definition of localtime. It is found on libc's localtime.o, but now we have a duplicated error. The reason it works with bfd is that bash doesn't use mktime directly and the undefined reference from libc is resolved to the libc implementation. It would also fail to link if bash itself directly used mktime. The bash-static configure test verifies that, for many values of t, either localtime(t) returns NULL or mktime(localtime(t)) == t. This test failed when localtime returned a truncated tm_year. This was fixed in tzcode in 2004 but has persisted in our tree since rS2708. Sponsored by: The FreeBSD Foundation
-rw-r--r--contrib/tzcode/stdtime/localtime.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/contrib/tzcode/stdtime/localtime.c b/contrib/tzcode/stdtime/localtime.c
index ad95082..632a8d4 100644
--- a/contrib/tzcode/stdtime/localtime.c
+++ b/contrib/tzcode/stdtime/localtime.c
@@ -1453,14 +1453,13 @@ localtime(const time_t *const timep)
}
_RWLOCK_RDLOCK(&lcl_rwlock);
tzset_basic(1);
- localsub(timep, 0L, p_tm);
+ p_tm = localsub(timep, 0L, p_tm);
_RWLOCK_UNLOCK(&lcl_rwlock);
- return(p_tm);
} else {
tzset_basic(0);
- localsub(timep, 0L, &tm);
- return(&tm);
+ p_tm = localsub(timep, 0L, &tm);
}
+ return(p_tm);
}
/*
@@ -1472,7 +1471,7 @@ localtime_r(const time_t *const timep, struct tm *tmp)
{
_RWLOCK_RDLOCK(&lcl_rwlock);
tzset_basic(1);
- localsub(timep, 0L, tmp);
+ tmp = localsub(timep, 0L, tmp);
_RWLOCK_UNLOCK(&lcl_rwlock);
return tmp;
}
OpenPOWER on IntegriCloud