Skip to content

Commit

Permalink
fix SIGSEGV inside gmmktime (VKCOM#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
astrophysik authored Mar 28, 2023
1 parent ce73a5b commit b2cf163
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion runtime/datetime/datetime_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "runtime/critical_section.h"
#include "runtime/datetime/timelib_wrapper.h"
#include "runtime/string_functions.h"
#include "server/server-log.h"

extern long timezone;

Expand All @@ -33,7 +34,7 @@ static void set_default_timezone_id(const char *timezone_id) {

static const char *suffix[] = {"st", "nd", "rd", "th"};

static time_t gmmktime(struct tm *tm) {
static time_t deprecated_gmmktime(struct tm * tm) {
char *tz = getenv("TZ");
setenv("TZ", "", 1);
tzset();
Expand All @@ -50,6 +51,24 @@ static time_t gmmktime(struct tm *tm) {
return result;
}

static time_t updated_gmmktime(struct tm * tm) {
return timegm(tm);
}

static time_t gmmktime(struct tm *tm) {
dl::CriticalSectionGuard critical_section;
time_t deprecated_time = deprecated_gmmktime(tm);
time_t updated_time = updated_gmmktime(tm);
if (deprecated_time != updated_time) {
char * tz = getenv("TZ");
log_server_warning("Updated gmmktime return different result. Updated value %ld. Deprecated value %ld. ENV TZ = \"%s\". "
"Local tz name[0] = \"%s\", tz name[1] = \"%s\", timezone %ld, daylight %d",
updated_time, deprecated_time, tz != nullptr ? tz : "null", tzname[0] != nullptr ? tzname[0] : "null",
tzname[1] != nullptr ? tzname[1] : "null", timezone, daylight);
}
return deprecated_time;
}

bool f$checkdate(int64_t month, int64_t day, int64_t year) {
return php_timelib_is_valid_date(month, day, year);
}
Expand Down

0 comments on commit b2cf163

Please sign in to comment.