Skip to content

Instantly share code, notes, and snippets.

@athoik
Created January 5, 2019 16:09
Show Gist options
  • Save athoik/91d6e7e7d5d42f318ed330b9597700da to your computer and use it in GitHub Desktop.
Save athoik/91d6e7e7d5d42f318ed330b9597700da to your computer and use it in GitHub Desktop.
POC to expose issue on parseDVBdate Enigma2 under aarch64
#include <stdio.h>
#include <ctime>
static void parseDVBdate(tm &t, int mjd)
{
int k;
printf("[eDVBLocalTimerHandler] parseDVBdate, mjd is %d\n", mjd);
t.tm_year = (int) ((mjd - 15078.2) / 365.25);
t.tm_mon = (int) ((mjd - 14956.1 - (int)(t.tm_year * 365.25)) / 30.6001);
t.tm_mday = (int) (mjd - 14956 - (int)(t.tm_year * 365.25) - (int)(t.tm_mon * 30.6001));
k = (t.tm_mon == 14 || t.tm_mon == 15) ? 1 : 0;
t.tm_year = t.tm_year + k;
t.tm_mon = t.tm_mon - 1 - k * 12;
t.tm_mon--;
printf("[eDVBLocalTimerHandler] parseDVBdate is %d:%d:%d\n", t.tm_year, t.tm_mon, t.tm_mday);
t.tm_isdst = 0;
t.tm_gmtoff = 0;
}
time_t parseDVBtime1(int mjd)
{
tm t;
parseDVBdate(t, mjd);
return timegm(&t);
}
time_t parseDVBtime2(int mjd)
{
tm t = {0};
parseDVBdate(t, mjd);
return timegm(&t);
}
int main()
{
std::time_t now = parseDVBtime1(12792);
char buffer[32];
std::strftime(buffer, 32, "%a, %d.%m.%Y %H:%M:%S", std::localtime(&now));
printf("parseDVBtime1 %s\n", buffer);
now = parseDVBtime2(12792);
std::strftime(buffer, 32, "%a, %d.%m.%Y %H:%M:%S", std::localtime(&now));
printf("parseDVBtime2 %s\n", buffer);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment