From 3318d8d5be273f92f77bda4debd8b9cfa25ea599 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Mon, 2 Apr 2018 18:52:47 +0200 Subject: [PATCH] [WINLOGON] Fix shutdown timeout format string for long timeout - Use the "%d days" format for timeouts longer than a day. - Fail if timeout is 10 years or longer. - TODO: Replace format strings by resources. German WinXP uses "%d days" instead of "%d Tage". We can do better! ;-) --- base/system/winlogon/shutdown.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/base/system/winlogon/shutdown.c b/base/system/winlogon/shutdown.c index d09368664aa..42452ca0678 100644 --- a/base/system/winlogon/shutdown.c +++ b/base/system/winlogon/shutdown.c @@ -16,6 +16,8 @@ /* DEFINES *******************************************************************/ #define SHUTDOWN_TIMER_ID 2000 +#define SECONDS_PER_DAY 86400 +#define SECONDS_PER_DECADE 315360000 /* STRUCTS *******************************************************************/ @@ -46,16 +48,25 @@ OnTimer( HWND hwndDlg, PSYS_SHUTDOWN_PARAMS pShutdownParams) { - WCHAR szBuffer[10]; - INT iSeconds, iMinutes, iHours; + WCHAR szBuffer[12]; + INT iSeconds, iMinutes, iHours, iDays; - iSeconds = (INT)pShutdownParams->dwTimeout; - iHours = iSeconds / 3600; - iSeconds -= iHours * 3600; - iMinutes = iSeconds / 60; - iSeconds -= iMinutes * 60; + if (pShutdownParams->dwTimeout < SECONDS_PER_DAY) + { + iSeconds = (INT)pShutdownParams->dwTimeout; + iHours = iSeconds / 3600; + iSeconds -= iHours * 3600; + iMinutes = iSeconds / 60; + iSeconds -= iMinutes * 60; + + swprintf(szBuffer, L"%02d:%02d:%02d", iHours, iMinutes, iSeconds); + } + else + { + iDays = (INT)(pShutdownParams->dwTimeout / SECONDS_PER_DAY); + swprintf(szBuffer, L"%d days", iDays); + } - swprintf(szBuffer, L"%02d:%02d:%02d", iHours, iMinutes, iSeconds); SetDlgItemTextW(hwndDlg, IDC_SYSSHUTDOWNTIMELEFT, szBuffer); if (pShutdownParams->dwTimeout == 0) @@ -185,6 +196,10 @@ StartSystemShutdown( { HANDLE hThread; + /* Fail if the timeout is 10 years or more */ + if (dwTimeout >= SECONDS_PER_DECADE) + return ERROR_INVALID_PARAMETER; + if (_InterlockedCompareExchange8((volatile char*)&g_ShutdownParams.bShuttingDown, TRUE, FALSE) == TRUE) return ERROR_SHUTDOWN_IN_PROGRESS;