VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-04-26 15:57:43 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-04-27 23:59:49 +0200
commitdc3bc64b8685aeec3ab461e632a1604833ed6fd6 (patch)
tree59aa850fb96aabe3212e946b5dfdce5d074a81e2 /src/Common
parent9ccb8a97afe66516b02da88b0997cc0d944a1010 (diff)
downloadVeraCrypt-dc3bc64b8685aeec3ab461e632a1604833ed6fd6.tar.gz
VeraCrypt-dc3bc64b8685aeec3ab461e632a1604833ed6fd6.zip
Windows: Better command line handling to make it more strict and robust. This avoids issues when using wrong syntax.
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Cmdline.c79
-rw-r--r--src/Common/Cmdline.h4
2 files changed, 10 insertions, 73 deletions
diff --git a/src/Common/Cmdline.c b/src/Common/Cmdline.c
index a455b982..178d938e 100644
--- a/src/Common/Cmdline.c
+++ b/src/Common/Cmdline.c
@@ -130,81 +130,26 @@ int GetArgSepPosOffset (char *lpszArgument)
return 0;
}
-int GetArgumentID (argumentspec *as, char *lpszArgument, int *nArgPos)
+int GetArgumentID (argumentspec *as, char *lpszArgument)
{
- char szTmp[MAX_PATH * 2];
int i;
- i = strlen (lpszArgument);
- szTmp[i] = 0;
- while (--i >= 0)
- {
- szTmp[i] = (char) tolower (lpszArgument[i]);
- }
-
for (i = 0; i < as->arg_cnt; i++)
{
- size_t k;
-
- k = strlen (as->args[i].long_name);
- if (memcmp (as->args[i].long_name, szTmp, k * sizeof (char)) == 0)
+ if (_stricmp (as->args[i].long_name, lpszArgument) == 0)
{
- int x;
- for (x = i + 1; x < as->arg_cnt; x++)
- {
- size_t m;
-
- m = strlen (as->args[x].long_name);
- if (memcmp (as->args[x].long_name, szTmp, m * sizeof (char)) == 0)
- {
- break;
- }
- }
-
- if (x == as->arg_cnt)
- {
- if (strlen (lpszArgument) != k)
- *nArgPos = k;
- else
- *nArgPos = 0;
- return as->args[i].Id;
- }
+ return as->args[i].Id;
}
}
for (i = 0; i < as->arg_cnt; i++)
{
- size_t k;
-
if (as->args[i].short_name[0] == 0)
continue;
- k = strlen (as->args[i].short_name);
- if (memcmp (as->args[i].short_name, szTmp, k * sizeof (char)) == 0)
+ if (_stricmp (as->args[i].short_name, lpszArgument) == 0)
{
- int x;
- for (x = i + 1; x < as->arg_cnt; x++)
- {
- size_t m;
-
- if (as->args[x].short_name[0] == 0)
- continue;
-
- m = strlen (as->args[x].short_name);
- if (memcmp (as->args[x].short_name, szTmp, m * sizeof (char)) == 0)
- {
- break;
- }
- }
-
- if (x == as->arg_cnt)
- {
- if (strlen (lpszArgument) != k)
- *nArgPos = k;
- else
- *nArgPos = 0;
- return as->args[i].Id;
- }
+ return as->args[i].Id;
}
}
@@ -212,27 +157,19 @@ int GetArgumentID (argumentspec *as, char *lpszArgument, int *nArgPos)
return -1;
}
-int GetArgumentValue (char **lpszCommandLineArgs, int nArgPos, int *nArgIdx,
+int GetArgumentValue (char **lpszCommandLineArgs, int *nArgIdx,
int nNoCommandLineArgs, char *lpszValue, int nValueSize)
{
*lpszValue = 0;
- if (nArgPos)
- {
- /* Handles the case of no space between parameter code and
- value */
- StringCbCopyA (lpszValue, nValueSize, &lpszCommandLineArgs[*nArgIdx][nArgPos]);
- lpszValue[nValueSize - 1] = 0;
- return HAS_ARGUMENT;
- }
- else if (*nArgIdx + 1 < nNoCommandLineArgs)
+ if (*nArgIdx + 1 < nNoCommandLineArgs)
{
int x = GetArgSepPosOffset (lpszCommandLineArgs[*nArgIdx + 1]);
if (x == 0)
{
/* Handles the case of space between parameter code
and value */
- StringCbCopyA (lpszValue, nValueSize, &lpszCommandLineArgs[*nArgIdx + 1][x]);
+ StringCbCopyA (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
lpszValue[nValueSize - 1] = 0;
(*nArgIdx)++;
return HAS_ARGUMENT;
diff --git a/src/Common/Cmdline.h b/src/Common/Cmdline.h
index 7192c537..8218c39b 100644
--- a/src/Common/Cmdline.h
+++ b/src/Common/Cmdline.h
@@ -33,8 +33,8 @@ typedef struct argumentspec_t
BOOL CALLBACK CommandHelpDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam );
int Win32CommandLine ( char *lpszCommandLine , char ***lpszArgs );
int GetArgSepPosOffset ( char *lpszArgument );
-int GetArgumentID ( argumentspec *as , char *lpszArgument , int *nArgPos );
-int GetArgumentValue ( char **lpszCommandLineArgs , int nArgPos , int *nArgIdx , int nNoCommandLineArgs , char *lpszValue , int nValueSize );
+int GetArgumentID ( argumentspec *as , char *lpszArgument );
+int GetArgumentValue ( char **lpszCommandLineArgs , int *nArgIdx , int nNoCommandLineArgs , char *lpszValue , int nValueSize );
#ifdef __cplusplus
}