summaryrefslogtreecommitdiff
path: root/ext/calendar/julian.c
diff options
context:
space:
mode:
authorGustavo André dos Santos Lopes <cataphract@php.net>2010-12-19 23:47:00 +0000
committerGustavo André dos Santos Lopes <cataphract@php.net>2010-12-19 23:47:00 +0000
commit433dff36d7df5e7703850c71121b10e9c6b725fe (patch)
tree2e35b5233159b382990382958ab586e75e3e4823 /ext/calendar/julian.c
parentd88515e1b830de22d3083cc66bb6d7ee5ec1811e (diff)
downloadphp-git-433dff36d7df5e7703850c71121b10e9c6b725fe.tar.gz
- Fixed bug #53574 (Integer overflow in SdnToJulian, sometimes leading to
segfault).
Diffstat (limited to 'ext/calendar/julian.c')
-rw-r--r--ext/calendar/julian.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/ext/calendar/julian.c b/ext/calendar/julian.c
index 39bcbc7e65..17e7bcb597 100644
--- a/ext/calendar/julian.c
+++ b/ext/calendar/julian.c
@@ -146,6 +146,7 @@
**************************************************************************/
#include "sdncal.h"
+#include <limits.h>
#define JULIAN_SDN_OFFSET 32083
#define DAYS_PER_5_MONTHS 153
@@ -164,15 +165,22 @@ void SdnToJulian(
int dayOfYear;
if (sdn <= 0) {
- *pYear = 0;
- *pMonth = 0;
- *pDay = 0;
- return;
+ goto fail;
}
- temp = (sdn + JULIAN_SDN_OFFSET) * 4 - 1;
+ /* Check for overflow */
+ if (sdn > (LONG_MAX - JULIAN_SDN_OFFSET * 4 + 1) / 4 || sdn < LONG_MIN / 4) {
+ goto fail;
+ }
+ temp = sdn * 4 + (JULIAN_SDN_OFFSET * 4 - 1);
/* Calculate the year and day of year (1 <= dayOfYear <= 366). */
- year = temp / DAYS_PER_4_YEARS;
+ {
+ long yearl = temp / DAYS_PER_4_YEARS;
+ if (yearl > INT_MAX || yearl < INT_MIN) {
+ goto fail;
+ }
+ year = (int) yearl;
+ }
dayOfYear = (temp % DAYS_PER_4_YEARS) / 4 + 1;
/* Calculate the month and day of month. */
@@ -196,6 +204,12 @@ void SdnToJulian(
*pYear = year;
*pMonth = month;
*pDay = day;
+ return;
+
+fail:
+ *pYear = 0;
+ *pMonth = 0;
+ *pDay = 0;
}
long int JulianToSdn(