Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIXED missing range check on MonthLengths array #157

Merged
merged 1 commit into from Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions greg.c
Expand Up @@ -50,6 +50,15 @@ int MonthLengths[][13] =
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};

int getMonthLength(int year, int month)
{
if (month < 0 || month > 13)
{
return 0;
}
return MonthLengths[LEAP (year)][month];
}

const char *ShortDayNames[] =
{
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
Expand Down
1 change: 1 addition & 0 deletions greg.h
Expand Up @@ -39,6 +39,7 @@ typedef struct dateStruct {
int yy; /* years since year 1 BCE i.e. -1 = 2 BCE */
} date_t;

int getMonthLength(int year, int month);
int dayOfYear( date_t );
long greg2abs( date_t );
date_t abs2greg(long);
Expand Down
3 changes: 2 additions & 1 deletion holidays.c
Expand Up @@ -33,6 +33,7 @@
#include "hebcal.h"
#include "common.h"
#include "danlib.h"
#include "greg.h"

#define _(String) lookup_translation(String)

Expand Down Expand Up @@ -775,7 +776,7 @@ void init_yahrtzeits( int hyear )
sscanf (monthStr, "%d", &inMonth);

if (inMonth > 12 || inMonth < 1 ||
inDay < 1 || inDay > MonthLengths[LEAP (inYear)][inMonth])
inDay < 1 || inDay > getMonthLength(inYear, inMonth))
{

warn ("Date out of range in yahrtzeit file. Skipping line %s",
Expand Down
4 changes: 2 additions & 2 deletions start.c
Expand Up @@ -765,7 +765,7 @@ void handleArgs(int argc, char *argv[])
{
if (theMonth > 12)
die("The month must be less than 13", "");
if (theDay > MonthLengths[LEAP(theYear)][theMonth])
if (theDay > getMonthLength(theYear, theMonth))
die("Sorry, there aren't that many days in %s (then)",
eMonths[theMonth]);
}
Expand Down Expand Up @@ -861,7 +861,7 @@ int main(int argc, char* argv[])
else
{
startAbs = greg2abs(tempDate);
tempDate.dd = MonthLengths[LEAP(theYear)][theMonth];
tempDate.dd = getMonthLength(theYear, theMonth);
endAbs = greg2abs(tempDate);
}
break;
Expand Down