2007-01-17 Marcus Brinkmann <marcus@g10code.de>

* w32-io.c (build_commandline): Quote all command line arguments.
	* w32-glib-io.c (build_commandline): Likewise.
This commit is contained in:
Marcus Brinkmann 2007-01-17 19:35:06 +00:00
parent cc5190ffc1
commit c1b1642f1b
3 changed files with 99 additions and 54 deletions

View File

@ -1,3 +1,8 @@
2007-01-17 Marcus Brinkmann <marcus@g10code.de>
* w32-io.c (build_commandline): Quote all command line arguments.
* w32-glib-io.c (build_commandline): Likewise.
2007-01-10 Werner Koch <wk@g10code.com> 2007-01-10 Werner Koch <wk@g10code.com>
* ttyname_r.c (ttyname_r) [W32]: Return a dummy name. * ttyname_r.c (ttyname_r) [W32]: Return a dummy name.

View File

@ -347,36 +347,56 @@ _gpgme_io_set_nonblocking (int fd)
static char * static char *
build_commandline ( char **argv ) build_commandline (char **argv)
{ {
int i, n = 0; int i;
char *buf, *p; int j;
int n = 0;
char *buf;
char *p;
/* We have to quote some things because under Windows the program
parses the commandline and does some unquoting. We enclose the
whole argument in double-quotes, and escape literal double-quotes
as well as backslashes with a backslash. We end up with a
trailing space at the end of the line, but that is harmless. */
for (i = 0; argv[i]; i++)
{
p = argv[i];
/* The leading double-quote. */
n++;
while (*p)
{
/* An extra one for each literal that must be escaped. */
if (*p == '\\' || *p == '"')
n++;
n++;
p++;
}
/* The trailing double-quote and the delimiter. */
n += 2;
}
/* And a trailing zero. */
n++;
/* FIXME: we have to quote some things because under Windows the
* program parses the commandline and does some unquoting. For now
* we only do very basic quoting to the first argument because this
* one often contains a space (e.g. C:\\Program Files\GNU\GnuPG\gpg.exe)
* and we would produce an invalid line in that case. */
for (i=0; argv[i]; i++)
n += strlen (argv[i]) + 2 + 1; /* 2 extra bytes for possible quoting */
buf = p = malloc (n); buf = p = malloc (n);
if ( !buf ) if (!buf)
return NULL; return NULL;
*buf = 0; for (i = 0; argv[i]; i++)
if ( argv[0] )
{ {
if (strpbrk (argv[0], " \t")) char *argvp = argv[i];
p = stpcpy (stpcpy (stpcpy (p, "\""), argv[0]), "\"");
else *(p++) = '"';
p = stpcpy (p, argv[0]); while (*argvp)
for (i = 1; argv[i]; i++)
{ {
if (!*argv[i]) if (*p == '\\' || *p == '"')
p = stpcpy (p, " \"\""); *(p++) = '\\';
else *(p++) = *(argvp++);
p = stpcpy (stpcpy (p, " "), argv[i]);
} }
*(p++) = '"';
*(p++) = ' ';
} }
*(p++) = 0;
return buf; return buf;
} }

View File

@ -799,36 +799,56 @@ _gpgme_io_set_nonblocking ( int fd )
static char * static char *
build_commandline ( char **argv ) build_commandline (char **argv)
{ {
int i, n = 0; int i;
char *buf, *p; int j;
int n = 0;
char *buf;
char *p;
/* We have to quote some things because under Windows the program
parses the commandline and does some unquoting. We enclose the
whole argument in double-quotes, and escape literal double-quotes
as well as backslashes with a backslash. We end up with a
trailing space at the end of the line, but that is harmless. */
for (i = 0; argv[i]; i++)
{
p = argv[i];
/* The leading double-quote. */
n++;
while (*p)
{
/* An extra one for each literal that must be escaped. */
if (*p == '\\' || *p == '"')
n++;
n++;
p++;
}
/* The trailing double-quote and the delimiter. */
n += 2;
}
/* And a trailing zero. */
n++;
/* FIXME: we have to quote some things because under Windows the
* program parses the commandline and does some unquoting. For now
* we only do very basic quoting to the first argument because this
* one often contains a space (e.g. C:\\Program Files\GNU\GnuPG\gpg.exe)
* and we would produce an invalid line in that case. */
for (i=0; argv[i]; i++)
n += strlen (argv[i]) + 2 + 1; /* 2 extra bytes for possible quoting */
buf = p = malloc (n); buf = p = malloc (n);
if ( !buf ) if (!buf)
return NULL; return NULL;
*buf = 0; for (i = 0; argv[i]; i++)
if ( argv[0] )
{ {
if (strpbrk (argv[0], " \t")) char *argvp = argv[i];
p = stpcpy (stpcpy (stpcpy (p, "\""), argv[0]), "\"");
else *(p++) = '"';
p = stpcpy (p, argv[0]); while (*argvp)
for (i = 1; argv[i]; i++)
{ {
if (!*argv[i]) if (*p == '\\' || *p == '"')
p = stpcpy (p, " \"\""); *(p++) = '\\';
else *(p++) = *(argvp++);
p = stpcpy (stpcpy (p, " "), argv[i]);
} }
*(p++) = '"';
*(p++) = ' ';
} }
*(p++) = 0;
return buf; return buf;
} }