From f156eb53457a9e4e34c1b96f9e54eb130dffd8a3 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 13 Apr 2015 16:21:22 +0300 Subject: Remove fatal error if strftime timestamp < 0. --- builtin.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index dde3121c..7aeccd5f 100644 --- a/builtin.c +++ b/builtin.c @@ -1913,8 +1913,16 @@ do_strftime(int nargs) lintwarn(_("strftime: received non-numeric second argument")); (void) force_number(t2); clock_val = get_number_si(t2); - if (clock_val < 0) - fatal(_("strftime: second argument less than 0 or too big for time_t")); + /* + * 4/2015: This used to be here: + * + * if (clock_val < 0) + * fatal(_("strftime: second argument less than 0 or too big for time_t")); + * + * It is now disabled since some systems have strftime that works + * on times before the epoch. No arbritrary limits comes into + * play at this point. + */ fclock = (time_t) clock_val; DEREF(t2); } -- cgit v1.2.3 From 3de71423b3a39be0b9536413321c953cbf99b119 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 14 Apr 2015 14:00:22 +0300 Subject: Improve negative time value checking for strftime. --- builtin.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 7aeccd5f..a7853d7c 100644 --- a/builtin.c +++ b/builtin.c @@ -1913,17 +1913,13 @@ do_strftime(int nargs) lintwarn(_("strftime: received non-numeric second argument")); (void) force_number(t2); clock_val = get_number_si(t2); + fclock = (time_t) clock_val; /* - * 4/2015: This used to be here: - * - * if (clock_val < 0) - * fatal(_("strftime: second argument less than 0 or too big for time_t")); - * - * It is now disabled since some systems have strftime that works - * on times before the epoch. No arbritrary limits comes into - * play at this point. + * 4/2015: Protect against negative value being assigned + * to unsigned time_t. */ - fclock = (time_t) clock_val; + if (clock_val < 0 && fclock > 0) + fatal(_("strftime: second argument less than 0 or too big for time_t")); DEREF(t2); } -- cgit v1.2.3 From a830a63718f1e9a0a812e772bef6e891668afd17 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 14 Apr 2015 15:02:27 +0300 Subject: Make indirect call of gensub with 3 args work. --- builtin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index a7853d7c..f650a9f8 100644 --- a/builtin.c +++ b/builtin.c @@ -3063,10 +3063,10 @@ call_sub(const char *name, int nargs) PUSH(rhs); nargs++; } - PUSH(rhs); + else + PUSH(rhs); } - unref(zero); result = do_sub(nargs, flags); if (flags != GENSUB) -- cgit v1.2.3 From 3fc38ff001d5a4345def6ce960918612ed209518 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 14 Apr 2015 15:57:53 +0300 Subject: Another bug fix in strftime. --- builtin.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index f650a9f8..fc670946 100644 --- a/builtin.c +++ b/builtin.c @@ -1943,6 +1943,9 @@ do_strftime(int nargs) else tm = localtime(& fclock); + if (tm == NULL) + return make_string("", 0); + bufp = buf; bufsize = sizeof(buf); for (;;) { -- cgit v1.2.3 From 5d781d9d27f2ab30679853317df3f5e9ad94be80 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 16 Apr 2015 13:14:06 +0300 Subject: Additional checking for strftime. --- builtin.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index fc670946..804bd60a 100644 --- a/builtin.c +++ b/builtin.c @@ -1864,7 +1864,7 @@ do_strftime(int nargs) NODE *t1, *t2, *t3, *ret; struct tm *tm; time_t fclock; - long clock_val; + double clock_val; char *bufp; size_t buflen, bufsize; char buf[BUFSIZ]; @@ -1873,6 +1873,8 @@ do_strftime(int nargs) int do_gmt; NODE *val = NULL; NODE *sub = NULL; + static const time_t time_t_min = TYPE_MINIMUM(time_t); + static const time_t time_t_max = TYPE_MAXIMUM(time_t); /* set defaults first */ format = def_strftime_format; /* traditional date format */ @@ -1912,7 +1914,7 @@ do_strftime(int nargs) if (do_lint && (t2->flags & (NUMCUR|NUMBER)) == 0) lintwarn(_("strftime: received non-numeric second argument")); (void) force_number(t2); - clock_val = get_number_si(t2); + clock_val = get_number_d(t2); fclock = (time_t) clock_val; /* * 4/2015: Protect against negative value being assigned @@ -1920,6 +1922,11 @@ do_strftime(int nargs) */ if (clock_val < 0 && fclock > 0) fatal(_("strftime: second argument less than 0 or too big for time_t")); + + /* And check that the value is in range */ + if (clock_val < time_t_min || clock_val > time_t_max) + fatal(_("strftime: second argument out of range for time_t")); + DEREF(t2); } -- cgit v1.2.3