[SHUTDOWN] Actually all shutdown.exe utilities from all Windows (>= XP) versions (and not just Vista+) support a comment string of up to 512, *EVEN IF* they mention in their help message that the comment can only be up to 127 characters long. I have really tested that ;-) (And what is more, shutdown's utility from Whistler support an arbitrary comment length!) So here I remove the code that imposes this limit and I just check for no more than 512 characters. I also fix an out-of-bounds check for argv.

This commit is contained in:
Hermès Bélusca-Maïto 2018-05-01 23:41:41 +02:00
parent 11f0e2c0f6
commit f34a30fec4
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 2 additions and 56 deletions

View file

@ -45,59 +45,6 @@ REASON shutdownReason[] =
{L"P" , 7, 0, SHTDN_REASON_MAJOR_POWER | SHTDN_REASON_MINOR_ENVIRONMENT} /* Legacy API shutdown (Planned) */
};
/*
* This command helps to work around the fact that the shutdown utility has
* different upper limits for the comment flag since each version of Windows
* seems to have different upper limits.
*/
BOOL CheckCommentLength(LPCWSTR comment)
{
DWORD finalLength = 0;
size_t strLength = 0;
DWORD osVersion = 0;
DWORD osMajorVersion = 0;
DWORD osMinorVersion = 0;
/* An empty string is always valid. */
if (!comment || *comment == 0)
return TRUE;
/* Grab the version of the current Operating System. */
osVersion = GetVersion();
osMajorVersion = (DWORD)(LOBYTE(LOWORD(osVersion)));
osMinorVersion = (DWORD)(HIBYTE(LOWORD(osVersion)));
/*
* Check to make sure that the proper length is being used
* based upon the version of Windows currently being used.
*/
if (osMajorVersion == 5) /* Windows XP/2003 */
{
if ((osMinorVersion == 1) || (osMinorVersion == 2))
{
finalLength = 127;
}
}
else if (osMajorVersion == 6) /* Windows Vista/7/2008 */
{
if ((osMinorVersion == 0) || (osMinorVersion == 1))
{
finalLength = 512;
}
}
/* Grab the length of the comment string. */
strLength = wcslen(comment);
/*
* Compare the size of the string to make sure
* it fits with the current version of Windows,
* and return TRUE or FALSE accordingly.
*/
return (strLength <= finalLength);
}
/*
* This function parses the reason code to a usable format that will specify
* why the user wants to shut the computer down. Although this is used for

View file

@ -52,7 +52,6 @@ extern const DWORD defaultReason;
/* PROTOTYPES *****************************************************************/
/* misc.c */
BOOL CheckCommentLength(LPCWSTR);
DWORD ParseReasonCode(LPCWSTR);
VOID DisplayError(DWORD dwError);

View file

@ -56,9 +56,9 @@ ParseArguments(struct CommandLineOptions* pOpts, int argc, WCHAR *argv[])
break;
case L'c': /* Comment on reason for shutdown */
if (index+1 > argc)
if (index+1 >= argc)
return ERROR_INVALID_DATA;
if(CheckCommentLength(argv[index+1]))
if (!argv[index+1] || wcslen(argv[index+1]) <= 512)
{
pOpts->message = argv[index+1];
index++;