From 503b156ec646f7692397c8708af7e29691a9533e Mon Sep 17 00:00:00 2001 From: "Matt Johnson (AZURE)" Date: Thu, 29 Aug 2019 16:11:05 -0700 Subject: [PATCH] Prevent cert creation failure on leap day --- cups/tls-sspi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cups/tls-sspi.c b/cups/tls-sspi.c index 6e3c03b9ec..1306b9a746 100644 --- a/cups/tls-sspi.c +++ b/cups/tls-sspi.c @@ -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);