1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

common,w32: Refine the command line parsing for \ in quotes.

* common/t-w32-cmdline.c (test_all): Add new test cases.
* common/w32-misc.c (strip_one_arg): Add arg endquote.
(parse_cmdstring): Take care of backslashes in quotes.
--

I found some new test vectors from Microsoft.
This commit is contained in:
Werner Koch 2021-03-04 12:30:30 +01:00
parent 8e15506d66
commit 20c6007686
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
2 changed files with 33 additions and 6 deletions

View file

@ -46,7 +46,7 @@ count_backslashes (const char *s)
static void
strip_one_arg (char *string)
strip_one_arg (char *string, int endquote)
{
char *s, *d;
unsigned int n, i;
@ -62,6 +62,12 @@ strip_one_arg (char *string)
if ((n&1)) /* Odd number of backslashes. */
*d++ = '"'; /* Print the quote. */
}
else if (!s[n] && endquote)
{
for (i=0; i < n/2; i++)
*d++ = '\\';
s--;
}
else /* Print all backslashes. */
{
for (i=0; i < n; i++)
@ -94,10 +100,21 @@ parse_cmdstring (char *string, char **argv)
{
if (*p == '\\' && p[1] == '"')
p++;
else if (*p == '\\' && p[1] == '\\')
p++;
else if (*p == '"')
{
if (argv && (p[1] == ' ' || p[1] == '\t' || !p[1]))
*p = 0;
if (p[1] == ' ' || p[1] == '\t' || !p[1])
{
if (argv)
{
*p = 0;
strip_one_arg (p0, 1);
argv[argc] = p0;
}
argc++;
p0 = NULL;
}
inquote = 0;
}
}
@ -126,7 +143,7 @@ parse_cmdstring (char *string, char **argv)
if (argv)
{
*p = 0;
strip_one_arg (p0);
strip_one_arg (p0, inquote);
argv[argc] = p0;
}
argc++;
@ -144,7 +161,7 @@ parse_cmdstring (char *string, char **argv)
if (argv)
{
*p = 0;
strip_one_arg (p0);
strip_one_arg (p0, inquote);
argv[argc] = p0;
}
argc++;