Skip to content

Commit 43f215a

Browse files
committed
- Fixed bug in SdnToGregorian (see comments on #53574, though that bug is about
another function). NEWS & tests tomorrow.
1 parent 5ad03cd commit 43f215a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

ext/calendar/gregor.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
**************************************************************************/
128128

129129
#include "sdncal.h"
130+
#include <limits.h>
130131

131132
#define GREGOR_SDN_OFFSET 32045
132133
#define DAYS_PER_5_MONTHS 153
@@ -146,19 +147,14 @@ void SdnToGregorian(
146147
long int temp;
147148
int dayOfYear;
148149

149-
if (sdn <= 0) {
150-
*pYear = 0;
151-
*pMonth = 0;
152-
*pDay = 0;
153-
return;
150+
if (sdn <= 0 ||
151+
sdn > (LONG_MAX - 4 * GREGOR_SDN_OFFSET) / 4) {
152+
goto fail;
154153
}
155154
temp = (sdn + GREGOR_SDN_OFFSET) * 4 - 1;
156155

157156
if (temp < 0) {
158-
*pYear = 0;
159-
*pMonth = 0;
160-
*pDay = 0;
161-
return;
157+
goto fail;
162158
}
163159

164160
/* Calculate the century (year/100). */
@@ -190,6 +186,10 @@ void SdnToGregorian(
190186
*pYear = year;
191187
*pMonth = month;
192188
*pDay = day;
189+
fail:
190+
*pYear = 0;
191+
*pMonth = 0;
192+
*pDay = 0;
193193
}
194194

195195
long int GregorianToSdn(

0 commit comments

Comments
 (0)