svn: /php/php-src/ branches/PHP_5_3/ext/calendar/gregor.c branches/PHP_5_4/ext/calendar/gregor.c trunk/ext/calendar/gregor.c
| From: | Gustavo André dos Santos Lopes | Date: | Mon, 26 Sep 2011 22:38:21 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_3/ext/calendar/gregor.c branches/PHP_5_4/ext/calendar/gregor.c trunk/ext/calendar/gregor.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-66667@lists.php.net to get a copy of this message | ||
cataphract Mon, 26 Sep 2011 22:38:21 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=317360
Log:
- Fixed bug in SdnToGregorian (see comments on #53574, though that bug is about
another function). NEWS & tests tomorrow.
Bug: https://bugs.php.net/53574 (Re-Opened) Integer
overflow in SdnToJulian
Changed paths:
U php/php-src/branches/PHP_5_3/ext/calendar/gregor.c
U php/php-src/branches/PHP_5_4/ext/calendar/gregor.c
U php/php-src/trunk/ext/calendar/gregor.c
Modified: php/php-src/branches/PHP_5_3/ext/calendar/gregor.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/calendar/gregor.c 2011-09-26 21:36:33 UTC (rev 317359)
+++ php/php-src/branches/PHP_5_3/ext/calendar/gregor.c 2011-09-26 22:38:21 UTC (rev 317360)
@@ -127,6 +127,7 @@
**************************************************************************/
#include "sdncal.h"
+#include <limits.h>
#define GREGOR_SDN_OFFSET 32045
#define DAYS_PER_5_MONTHS 153
@@ -146,19 +147,14 @@
long int temp;
int dayOfYear;
- if (sdn <= 0) {
- *pYear = 0;
- *pMonth = 0;
- *pDay = 0;
- return;
+ if (sdn <= 0 ||
+ sdn > (LONG_MAX - 4 * GREGOR_SDN_OFFSET) / 4) {
+ goto fail;
}
temp = (sdn + GREGOR_SDN_OFFSET) * 4 - 1;
if (temp < 0) {
- *pYear = 0;
- *pMonth = 0;
- *pDay = 0;
- return;
+ goto fail;
}
/* Calculate the century (year/100). */
@@ -190,6 +186,10 @@
*pYear = year;
*pMonth = month;
*pDay = day;
+fail:
+ *pYear = 0;
+ *pMonth = 0;
+ *pDay = 0;
}
long int GregorianToSdn(
Modified: php/php-src/branches/PHP_5_4/ext/calendar/gregor.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/calendar/gregor.c 2011-09-26 21:36:33 UTC (rev 317359)
+++ php/php-src/branches/PHP_5_4/ext/calendar/gregor.c 2011-09-26 22:38:21 UTC (rev 317360)
@@ -127,6 +127,7 @@
**************************************************************************/
#include "sdncal.h"
+#include <limits.h>
#define GREGOR_SDN_OFFSET 32045
#define DAYS_PER_5_MONTHS 153
@@ -146,19 +147,14 @@
long int temp;
int dayOfYear;
- if (sdn <= 0) {
- *pYear = 0;
- *pMonth = 0;
- *pDay = 0;
- return;
+ if (sdn <= 0 ||
+ sdn > (LONG_MAX - 4 * GREGOR_SDN_OFFSET) / 4) {
+ goto fail;
}
temp = (sdn + GREGOR_SDN_OFFSET) * 4 - 1;
if (temp < 0) {
- *pYear = 0;
- *pMonth = 0;
- *pDay = 0;
- return;
+ goto fail;
}
/* Calculate the century (year/100). */
@@ -190,6 +186,10 @@
*pYear = year;
*pMonth = month;
*pDay = day;
+fail:
+ *pYear = 0;
+ *pMonth = 0;
+ *pDay = 0;
}
long int GregorianToSdn(
Modified: php/php-src/trunk/ext/calendar/gregor.c
===================================================================
--- php/php-src/trunk/ext/calendar/gregor.c 2011-09-26 21:36:33 UTC (rev 317359)
+++ php/php-src/trunk/ext/calendar/gregor.c 2011-09-26 22:38:21 UTC (rev 317360)
@@ -127,6 +127,7 @@
**************************************************************************/
#include "sdncal.h"
+#include <limits.h>
#define GREGOR_SDN_OFFSET 32045
#define DAYS_PER_5_MONTHS 153
@@ -146,19 +147,14 @@
long int temp;
int dayOfYear;
- if (sdn <= 0) {
- *pYear = 0;
- *pMonth = 0;
- *pDay = 0;
- return;
+ if (sdn <= 0 ||
+ sdn > (LONG_MAX - 4 * GREGOR_SDN_OFFSET) / 4) {
+ goto fail;
}
temp = (sdn + GREGOR_SDN_OFFSET) * 4 - 1;
if (temp < 0) {
- *pYear = 0;
- *pMonth = 0;
- *pDay = 0;
- return;
+ goto fail;
}
/* Calculate the century (year/100). */
@@ -190,6 +186,10 @@
*pYear = year;
*pMonth = month;
*pDay = day;
+fail:
+ *pYear = 0;
+ *pMonth = 0;
+ *pDay = 0;
}
long int GregorianToSdn(