Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
handle wrong timezone properly
Browse files Browse the repository at this point in the history
  • Loading branch information
weigon committed Jun 15, 2018
1 parent ceaee07 commit fa95013
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/http/src/http_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ time_t time_from_rfc5322_fixdate(const char *date_buf) {

char wday[4];
char mon[4];
if (7 != sscanf(date_buf, "%3s, %2u %3s %4u %2u:%2u:%2u GMT",
char timezone_s[4];
if (8 != sscanf(date_buf, "%3s, %2u %3s %4u %2u:%2u:%2u %3s",
wday,
&t_m.tm_mday,
mon,
&t_m.tm_year,
&t_m.tm_hour,
&t_m.tm_min,
&t_m.tm_sec
&t_m.tm_sec,
timezone_s
)) {
throw std::out_of_range("invalid date");
}
Expand Down Expand Up @@ -127,6 +129,9 @@ time_t time_from_rfc5322_fixdate(const char *date_buf) {
if (t_m.tm_year < 1900) {
throw std::out_of_range("year too small");
}
if (std::string(timezone_s) != "GMT") {
throw std::out_of_range("invalid timezone");
}
t_m.tm_year -= 1900;

return time_from_struct_tm_utc(&t_m);
Expand Down
1 change: 0 additions & 1 deletion src/http/tests/test_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ INSTANTIATE_TEST_CASE_P(HttpTimeParses,
));

TEST_P(HttpTimeThrowsTest, time_from_rfc5322_fixdate_p) {
SCOPED_TRACE("// year before 1900");
EXPECT_THROW(time_from_rfc5322_fixdate(GetParam()), std::out_of_range);
}

Expand Down

0 comments on commit fa95013

Please sign in to comment.