]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/commit
MFC r313774: localtime: return NULL if time_t out of range of struct tm
authoremaste <emaste@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 1 Mar 2017 01:44:40 +0000 (01:44 +0000)
committeremaste <emaste@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 1 Mar 2017 01:44:40 +0000 (01:44 +0000)
commit48914cf07cf37a35f7f2c3d52dc5c5d89b6cc056
tree1101db9c5a808bf876ed073a1381ea29d4f012d1
parent1f2aa270b655ac3523b67330d8d1968b675d0830
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

git-svn-id: svn://svn.freebsd.org/base/stable/10@314446 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
contrib/tzcode/stdtime/localtime.c