Skip to content

Commit

Permalink
Prevent cert creation failure on leap day
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint committed Aug 29, 2019
1 parent bc5060a commit 503b156
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cups/tls-sspi.c
Expand Up @@ -1968,6 +1968,11 @@ http_sspi_make_credentials(
GetSystemTime(&et);
et.wYear += years;

// If today is February 29th, and the above addition operation results in a year that is *not* a leap year,
// then use February 28th instead. Otherwise CertCreateSelfSignCertificate would fail.
bool isLeapYear = et.wYear % 4 == 0 && (et.wYear % 100 != 0 || et.wYear % 400 == 0);
et.wDay = et.wMonth == 2 && et.wDay == 29 && !isLeapYear ? 28 : et.wDay;

ZeroMemory(&exts, sizeof(exts));

createdContext = CertCreateSelfSignCertificate(hProv, &sib, 0, &kpi, NULL, NULL, &et, &exts);
Expand Down

0 comments on commit 503b156

Please sign in to comment.