Skip to content

Commit

Permalink
dcrt0.cc: Untangle allow_glob from winshell
Browse files Browse the repository at this point in the history
Otherwise if globbing is allowed and we get called from a
Windows program, build_argv thinks we've been called from
a Cygwin program.
  • Loading branch information
mingwandroid authored and lazka committed Jun 18, 2023
1 parent d9d7bda commit 8a7e2c8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions winsup/cygwin/dcrt0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ isquote (char c)

/* Step over a run of characters delimited by quotes */
static /*__inline*/ char *
quoted (char *cmd, int winshell)
quoted (char *cmd, int winshell, int glob)
{
char *p;
char quote = *cmd;

if (!winshell)
if (!winshell || !glob)
{
char *p;
strcpy (cmd, cmd + 1);
Expand All @@ -169,8 +169,8 @@ quoted (char *cmd, int winshell)
}

const char *s = quote == '\'' ? "'" : "\\\"";
/* This must have been run from a Windows shell, so preserve
quotes for globify to play with later. */
/* This must have been run from a Windows shell and globbing is enabled,
so preserve quotes for globify to play with later. */
while (*cmd && *++cmd)
if ((p = strpbrk (cmd, s)) == NULL)
{
Expand Down Expand Up @@ -291,7 +291,7 @@ globify (char *word, char **&argv, int &argc, int &argvlen)
/* Build argv, argc from string passed from Windows. */

static void
build_argv (char *cmd, char **&argv, int &argc, int winshell)
build_argv (char *cmd, char **&argv, int &argc, int winshell, int glob)
{
int argvlen = 0;
int nesting = 0; // monitor "nesting" from insert_file
Expand Down Expand Up @@ -325,7 +325,7 @@ build_argv (char *cmd, char **&argv, int &argc, int winshell)
a Cygwin process, or if the word starts with a '@'.
In this case, the insert_file function needs an unquoted
DOS filename and globbing isn't performed anyway. */
cmd = quoted (cmd, winshell && argc > 0 && *word != '@');
cmd = quoted (cmd, winshell && argc > 0 && *word != '@', glob);
}
if (issep (*cmd)) // End of argument if space
break;
Expand All @@ -351,7 +351,7 @@ build_argv (char *cmd, char **&argv, int &argc, int winshell)
}

/* Add word to argv file after (optional) wildcard expansion. */
if (!winshell || !argc || !globify (word, argv, argc, argvlen))
if (!glob || !argc || !globify (word, argv, argc, argvlen))
{
debug_printf ("argv[%d] = '%s'", argc, word);
argv[argc++] = word;
Expand Down Expand Up @@ -903,6 +903,7 @@ dll_crt0_1 (void *)
/* Scan the command line and build argv. Expand wildcards if not
called from another cygwin process. */
build_argv (line, __argv, __argc,
NOTSTATE (myself, PID_CYGPARENT),
NOTSTATE (myself, PID_CYGPARENT) && allow_glob);

/* Convert argv[0] to posix rules if it's currently blatantly
Expand Down

0 comments on commit 8a7e2c8

Please sign in to comment.