From dc3bc64b8685aeec3ab461e632a1604833ed6fd6 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 26 Apr 2015 15:57:43 +0200 Subject: Windows: Better command line handling to make it more strict and robust. This avoids issues when using wrong syntax. --- src/Format/Tcformat.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'src/Format') diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c index b32ce0ce..2bff1963 100644 --- a/src/Format/Tcformat.c +++ b/src/Format/Tcformat.c @@ -7831,7 +7831,6 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine) { OptionHistory, OptionNoIsoCheck, - OptionQuit, OptionTokenLib, CommandResumeSysEncLogOn, CommandResumeSysEnc, @@ -7848,7 +7847,6 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine) { { OptionHistory, "/history", "/h", FALSE }, { OptionNoIsoCheck, "/noisocheck", "/n", FALSE }, - { OptionQuit, "/quit", "/q", FALSE }, { OptionTokenLib, "/tokenlib", NULL, FALSE }, { CommandResumeSysEncLogOn, "/acsysenc", "/a", TRUE }, @@ -7864,7 +7862,6 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine) argumentspec as; - int nArgPos; int x; if (lpszCommandLineArgs[i] == NULL) @@ -7873,7 +7870,7 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine) as.args = args; as.arg_cnt = sizeof(args)/ sizeof(args[0]); - x = GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos); + x = GetArgumentID (&as, lpszCommandLineArgs[i]); switch (x) { @@ -8004,37 +8001,33 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine) case OptionHistory: { - char szTmp[8]; - GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs, - szTmp, sizeof (szTmp)); - if (!_stricmp(szTmp,"y") || !_stricmp(szTmp,"yes")) - { - bHistory = TRUE; - bHistoryCmdLine = TRUE; - } + char szTmp[8] = {0}; + bHistory = bHistoryCmdLine = TRUE; - if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no")) + if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, + szTmp, sizeof (szTmp))) { - bHistory = FALSE; - bHistoryCmdLine = TRUE; + if (!_stricmp(szTmp,"y") || !_stricmp(szTmp,"yes")) + { + bHistory = TRUE; + } + + else if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no")) + { + bHistory = FALSE; + } + else + AbortProcess ("COMMAND_LINE_ERROR"); } } break; case OptionTokenLib: - if (GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs, SecurityTokenLibraryPath, sizeof (SecurityTokenLibraryPath)) == HAS_ARGUMENT) + if (GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, SecurityTokenLibraryPath, sizeof (SecurityTokenLibraryPath)) == HAS_ARGUMENT) InitSecurityTokenLibrary(hwndDlg); else - Error ("COMMAND_LINE_ERROR", hwndDlg); - - break; + AbortProcess ("COMMAND_LINE_ERROR"); - case OptionQuit: - { - // Used to indicate non-install elevation - char szTmp[32]; - GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)); - } break; default: -- cgit v1.2.3