summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-12-25 09:57:07 -0800
committerSteve Hay <steve.m.hay@googlemail.com>2015-01-11 13:47:46 +0000
commit02ce2b5bb801c69d1297c2a00c068bedb87f9e28 (patch)
tree513fafb3430d12da4a9be40001c8d5aebe824823 /pp_sys.c
parentc5bd8a7b100f4a62407c1186848361543aab0bb9 (diff)
downloadperl-02ce2b5bb801c69d1297c2a00c068bedb87f9e28.tar.gz
[perl #123495] Stop gmtime(nan) from crashing
We were getting a time struct like this: $12 = { tm_sec = -2147483588, tm_min = 2147483647, tm_hour = -2147483624, tm_mday = -2147483647, tm_mon = 11, tm_year = 69, tm_wday = -2147483641, tm_yday = -2147483314, tm_isdst = 0, tm_gmtoff = 0, tm_zone = 0x1004f6bb6 "UTC" } which resulted in dayname[tmbuf.tm_wday] reading past the beginning of the array. We should check for nan explicitly instead of falling through to the time calculations. (cherry picked from commit d8bd3d828a02f8df716063d9980b8b9af539ca42)
Diffstat (limited to 'pp_sys.c')
-rw-r--r--pp_sys.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/pp_sys.c b/pp_sys.c
index a4172ac55d..af9cc844f1 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -4460,11 +4460,16 @@ PP(pp_gmtime)
}
else {
NV input = Perl_floor(POPn);
+ const bool isnan = Perl_isnan(input);
when = (Time64_T)input;
- if (when != input) {
+ if (UNLIKELY(isnan || when != input)) {
/* diag_listed_as: gmtime(%f) too large */
Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW),
"%s(%.0" NVff ") too large", opname, input);
+ if (isnan) {
+ err = NULL;
+ goto failed;
+ }
}
}
@@ -4490,6 +4495,7 @@ PP(pp_gmtime)
if (err == NULL) {
/* diag_listed_as: gmtime(%f) failed */
/* XXX %lld broken for quads */
+ failed:
Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW),
"%s(%.0" NVff ") failed", opname, when);
}