Skip to content

Commit

Permalink
libcore: Validity check in date parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent bd3268e commit 4a6df08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions doomsday/libs/core/include/de/data/time.h
Expand Up @@ -149,12 +149,12 @@ class DE_PUBLIC Time : public ISerializable
SecondsSinceStart,
BuildNumberAndSecondsSinceStart,
FriendlyFormat,
ISODateOnly, // yyyy-MM-dd
ISODateOnly, // yyyy-MM-dd
CompilerDateTime, // Oct 7 2013 03:18:36 (__DATE__ __TIME__)
HumanDate, ///< human-entered date (only with Time::fromText)
HumanDate, ///< human-entered date (only with Time::fromText)
UnixLsStyleDateTime,
};

using TimePoint = std::chrono::system_clock::time_point;

public:
Expand Down
6 changes: 5 additions & 1 deletion doomsday/libs/core/src/data/time.cpp
Expand Up @@ -531,7 +531,7 @@ Time Time::parse(const String &text, const char *format) // static
}
if (is.fail()) return Time::invalidTime();
}

// Assume missing date values.
if (year == 0)
{
Expand All @@ -546,6 +546,10 @@ Time Time::parse(const String &text, const char *format) // static
day = 1;
}

// In the valid range?
if (month < 1 || month > 12) return Time::invalidTime();
if (day < 1 || day > 31) return Time::invalidTime();

return Time(year, month, day, hour, minute, 0);
}

Expand Down

0 comments on commit 4a6df08

Please sign in to comment.