Skip to content

Commit

Permalink
Merge pull request #4554 from ArqamFarooqui110719/issue/4541
Browse files Browse the repository at this point in the history
fix for wrong date values
  • Loading branch information
fgalan authored Jun 7, 2024
2 parents b8ee58d + 3d2a20e commit 17bb087
Show file tree
Hide file tree
Showing 5 changed files with 818 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix: wrong date values should not allowed in subscription's expires field (#4541)
66 changes: 66 additions & 0 deletions src/lib/common/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,53 @@ static int timezoneOffset(const char* tz)



/*****************************************************************************
*
* isLeapYear -
*
* This code will check, if the given year is a leap year or not.
*
*/
bool isLeapYear(int year)
{
// ref: https://www.geeksforgeeks.org/program-check-given-year-leap-year/
if (year % 400 == 0)
{
return true;
}
if ((year % 4 == 0) && (year % 100 != 0))
{
return true;
}
return false;
}



/*****************************************************************************
*
* daysInMonth -
*
* This code will check correct number of days in given month.
*
*/
int daysInMonth(int year, int month)
{
if (month == 1) //february
{
return isLeapYear(year) ? 29 : 28;
}
// for April, June, September, November
if (month == 3 || month == 5 || month == 8 || month == 10)
{
return 30;
}
// For all other months (Jan, March, May, July, Aug, October, December)
return 31;
}



/*****************************************************************************
*
* parse8601Time -
Expand Down Expand Up @@ -606,6 +653,25 @@ double parse8601Time(const std::string& ss)
time.tm_min = m; // 0-59
time.tm_sec = (int) s; // 0-61 (0-60 in C++11)

const int minYear = 0;
const int minMonth = 0;
const int maxMonth = 11;
const int minDay = 1;
const int maxDay = daysInMonth(y, time.tm_mon);;
const int minHour = 0;
const int maxHour = 23;
const int minMinute = 0;
const int maxMinute = 59;
const int minSecond = 0;
const int maxSecond = 59;

if (time.tm_year < minYear || time.tm_mon < minMonth || time.tm_mon > maxMonth || time.tm_mday < minDay ||
time.tm_mday > maxDay || time.tm_hour < minHour || time.tm_hour > maxHour || time.tm_min < minMinute ||
time.tm_min > maxMinute || time.tm_sec < minSecond || time.tm_sec > maxSecond)
{
return -1;
}

int64_t totalSecs = timegm(&time) - offset;
float millis = s - (int) s;
double timestamp = totalSecs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ payload='{
"timestamp_0":
{
"type": "DateTime",
"value": "017-06-17T07:21:24.238Z",
"value": "2017-06-17T07:21:24.238Z",
"metadata": {
"very_hot_1":
{
Expand Down
Loading

0 comments on commit 17bb087

Please sign in to comment.