1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-23 09:10:43 +00:00

Fix an issue related to mktime(3) returning -1 when tm_isdst is true but the timestamp cannot be represented. Previously, -1 was interpreted as a valid result leading erlang:localtime_to_universaltime/2 to return {{1969, 12, 31}, {23, 59, 59}}.

A detailed explanation may be found here:

  http://www.erlang.org/pipermail/erlang-bugs/2008-November/001077.html

Obtained from:	Paul Guyot <pguyot at kallisys.net>
This commit is contained in:
Jimmy Olgeni 2008-11-17 21:30:16 +00:00
parent bf45b7890f
commit 8998cb5c9a
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=222989
6 changed files with 90 additions and 2 deletions

View File

@ -7,7 +7,7 @@
PORTNAME= erlang
PORTVERSION= r12b5
PORTREVISION= 1
PORTREVISION= 2
PORTEPOCH= 1
CATEGORIES= lang parallel java
MASTER_SITES= http://www.erlang.org/download/ \

View File

@ -0,0 +1,15 @@
$FreeBSD$
--- erts/emulator/beam/erl_time_sup.c.orig
+++ erts/emulator/beam/erl_time_sup.c
@@ -648,6 +648,9 @@
t.tm_sec = *second;
t.tm_isdst = isdst;
the_clock = mktime(&t);
+ if (the_clock == -1) {
+ return 0;
+ }
#ifdef HAVE_GMTIME_R
gmtime_r(&the_clock, (tm = &tmbuf));
#else

View File

@ -0,0 +1,29 @@
$FreeBSD$
--- lib/stdlib/src/calendar.erl.orig
+++ lib/stdlib/src/calendar.erl
@@ -215,11 +215,19 @@
-spec local_time_to_universal_time_dst(t_datetime1970()) -> [t_datetime1970()].
local_time_to_universal_time_dst(DateTime) ->
- UtDst = erlang:localtime_to_universaltime(DateTime, true),
- Ut = erlang:localtime_to_universaltime(DateTime, false),
%% Reverse check the universal times
- LtDst = erlang:universaltime_to_localtime(UtDst),
- Lt = erlang:universaltime_to_localtime(Ut),
+ {UtDst, LtDst} =
+ try
+ UtDst0 = erlang:localtime_to_universaltime(DateTime, true),
+ {UtDst0, erlang:universaltime_to_localtime(UtDst0)}
+ catch error:badarg -> {error, error}
+ end,
+ {Ut, Lt} =
+ try
+ Ut0 = erlang:localtime_to_universaltime(DateTime, false),
+ {Ut0, erlang:universaltime_to_localtime(Ut0)}
+ catch error:badarg -> {error, error}
+ end,
%% Return the valid universal times
case {LtDst,Lt} of
{DateTime,DateTime} when UtDst =/= Ut ->

View File

@ -7,7 +7,7 @@
PORTNAME= erlang
PORTVERSION= r12b5
PORTREVISION= 1
PORTREVISION= 2
PORTEPOCH= 1
CATEGORIES= lang parallel java
MASTER_SITES= http://www.erlang.org/download/ \

View File

@ -0,0 +1,15 @@
$FreeBSD$
--- erts/emulator/beam/erl_time_sup.c.orig
+++ erts/emulator/beam/erl_time_sup.c
@@ -648,6 +648,9 @@
t.tm_sec = *second;
t.tm_isdst = isdst;
the_clock = mktime(&t);
+ if (the_clock == -1) {
+ return 0;
+ }
#ifdef HAVE_GMTIME_R
gmtime_r(&the_clock, (tm = &tmbuf));
#else

View File

@ -0,0 +1,29 @@
$FreeBSD$
--- lib/stdlib/src/calendar.erl.orig
+++ lib/stdlib/src/calendar.erl
@@ -215,11 +215,19 @@
-spec local_time_to_universal_time_dst(t_datetime1970()) -> [t_datetime1970()].
local_time_to_universal_time_dst(DateTime) ->
- UtDst = erlang:localtime_to_universaltime(DateTime, true),
- Ut = erlang:localtime_to_universaltime(DateTime, false),
%% Reverse check the universal times
- LtDst = erlang:universaltime_to_localtime(UtDst),
- Lt = erlang:universaltime_to_localtime(Ut),
+ {UtDst, LtDst} =
+ try
+ UtDst0 = erlang:localtime_to_universaltime(DateTime, true),
+ {UtDst0, erlang:universaltime_to_localtime(UtDst0)}
+ catch error:badarg -> {error, error}
+ end,
+ {Ut, Lt} =
+ try
+ Ut0 = erlang:localtime_to_universaltime(DateTime, false),
+ {Ut0, erlang:universaltime_to_localtime(Ut0)}
+ catch error:badarg -> {error, error}
+ end,
%% Return the valid universal times
case {LtDst,Lt} of
{DateTime,DateTime} when UtDst =/= Ut ->