# [PATCH] Fix potential int overflow in date extension.

- Thread: https://externals.io/message/80845
- Original archive: https://news-web.php.net/php.internals/80845
- Started by Joshua Rogers on 2015-01-19T19:15:58+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #80845 — Joshua Rogers — 2015-01-19T19:15:58+00:00

URL: https://externals.io/message/80845#80845

---
 ext/date/lib/tm2unixtime.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ext/date/lib/tm2unixtime.c b/ext/date/lib/tm2unixtime.c
index c058672..94e5254 100644
--- a/ext/date/lib/tm2unixtime.c
+++ b/ext/date/lib/tm2unixtime.c
@@ -334,9 +334,9 @@ static timelib_sll do_years(timelib_sll year)
 static timelib_sll do_months(timelib_ull month, timelib_ull year)
 {
 	if (timelib_is_leap(year)) {
-		return ((month_tab_leap[month - 1] + 1) * SECS_PER_DAY);
+		return (((timelib_ull)month_tab_leap[month - 1] + 1) * SECS_PER_DAY);
 	} else {
-		return ((month_tab[month - 1]) * SECS_PER_DAY);
+		return (((timelib_ull)month_tab[month - 1]) * SECS_PER_DAY);
 	}
 }
 
@@ -361,7 +361,7 @@ static timelib_sll do_adjust_timezone(timelib_time *tz, timelib_tzinfo *tzi)
 		case TIMELIB_ZONETYPE_OFFSET:
 
 			tz->is_localtime = 1;
-			return tz->z * 60;
+			return (timelib_sll)tz->z * 60;
 			break;
 
 		case TIMELIB_ZONETYPE_ABBR: {
-- 
1.9.1

---

## #80846 — Joshua Rogers — 2015-01-19T19:23:04+00:00

URL: https://externals.io/message/80845#80846 · In reply to: #80845

> --
>  ext/date/lib/tm2unixtime.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
Somebody please take a look at /ext/date/lib/parse_tz.c too:

438timelib_sll timelib_get_current_offset(timelib_time *t)
[..]
446                        return (t->z + t->dst) * -60;
Should that be cast timelib_sll too?

I think perhaps the function should be an int, seeing as it looks like
the result should be negative. Somebody please check.


-- 
-- Joshua Rogers <https://internot.info/

---

## #81182 — Yasuo Ohgaki — 2015-01-27T00:25:53+00:00

URL: https://externals.io/message/80845#81182 · In reply to: #80846

Hi all,



> 
> > […]
> Somebody please take a look at /ext/date/lib/parse_tz.c too:
>
> 438timelib_sll timelib_get_current_offset(timelib_time *t)
> [..]
> 446                        return (t->z + t->dst) * -60;
> Should that be cast timelib_sll too?
>
> I think perhaps the function should be an int, seeing as it looks like
> the result should be negative. Somebody please check.


I'm not familiar with timelib. Anyway, if you could send PR, it would be
nicer.
Or at least a bug report.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #81213 — Derick Rethans — 2015-01-27T09:42:15+00:00

URL: https://externals.io/message/80845#81213 · In reply to: #80846

> 
> > […]
> Somebody please take a look at /ext/date/lib/parse_tz.c too:
> 
> 438timelib_sll timelib_get_current_offset(timelib_time *t)
> [..]
> 446                        return (t->z + t->dst) * -60;
> Should that be cast timelib_sll too?
> 
> I think perhaps the function should be an int, seeing as it looks like
> the result should be negative. Somebody please check.

The result can be either positive or negative as t->z can be both. 
timelib_sll seems right though, as it stands for "long long signed".
I don't quite see how this can overflow though - as t->z and t->dst come 
just close to 100000 (and it's internal provided data).

cheers,
Derick

-- 
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine
