https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f34a30fec4705422bd80c…
commit f34a30fec4705422bd80cff6a46e818b0a65be8a
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Tue May 1 23:41:41 2018 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Wed May 2 00:24:10 2018 +0200
[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-bound [...]
---
base/applications/shutdown/misc.c | 53 -----------------------------------
base/applications/shutdown/precomp.h | 1 -
base/applications/shutdown/shutdown.c | 4 +--
3 files changed, 2 insertions(+), 56 deletions(-)
diff --git a/base/applications/shutdown/misc.c b/base/applications/shutdown/misc.c
index d7949376b5..462672df37 100644
--- a/base/applications/shutdown/misc.c
+++ b/base/applications/shutdown/misc.c
@@ -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
diff --git a/base/applications/shutdown/precomp.h b/base/applications/shutdown/precomp.h
index f13ce2b0d4..a63cc470a5 100644
--- a/base/applications/shutdown/precomp.h
+++ b/base/applications/shutdown/precomp.h
@@ -52,7 +52,6 @@ extern const DWORD defaultReason;
/* PROTOTYPES *****************************************************************/
/* misc.c */
-BOOL CheckCommentLength(LPCWSTR);
DWORD ParseReasonCode(LPCWSTR);
VOID DisplayError(DWORD dwError);
diff --git a/base/applications/shutdown/shutdown.c
b/base/applications/shutdown/shutdown.c
index 3e492b9d90..f4c403d1ae 100644
--- a/base/applications/shutdown/shutdown.c
+++ b/base/applications/shutdown/shutdown.c
@@ -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++;