pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
10+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2019-10-28 f88544904e  On Windows, use COMSPEC to find the location of cmd.exe.
* BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
@ 2019-10-26 04:30 PG Bug reporting form <noreply@postgresql.org>
  2019-10-26 13:36 ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 10+ messages in thread

From: PG Bug reporting form @ 2019-10-26 04:30 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: cilizili@protonmail.com

The following bug has been logged on the website:

Bug reference:      16080
Logged by:          cili
Email address:      cilizili@protonmail.com
PostgreSQL version: 12.0
Operating system:   Microsoft Windows [Version 10.0.18362.418]
Description:        

If a fake cmd.exe exits in the current directory, pg_ctl is failed to
start.

Instructions:
# cd %TEMP%
# "c:\Program Files\PostgreSQL\12\bin\pg_ctl.exe" initdb -D test
# copy %windir%\system32\calc.exe cmd.exe
# "c:\Program Files\PostgreSQL\12\bin\pg_ctl.exe" start -D test
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.

Expected:
The PostgreSQL is started.

Actual:
The Windows calculator instead of PostgreSQL is started.



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
  2019-10-26 04:30 BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. PG Bug reporting form <noreply@postgresql.org>
@ 2019-10-26 13:36 ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 14:15   ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Tom Lane @ 2019-10-26 13:36 UTC (permalink / raw)
  To: cilizili@protonmail.com; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> If a fake cmd.exe exits in the current directory, pg_ctl is failed to
> start.

I do not think this is a bug.  There are probably thousands of ways to
break Postgres by misconfiguring your system, and this is one of 'em.

(Likewise for your identical complaint about pg_upgrade.)

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
  2019-10-26 04:30 BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. PG Bug reporting form <noreply@postgresql.org>
  2019-10-26 13:36 ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-10-26 14:15   ` Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 15:20     ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 10+ messages in thread

From: Juan José Santamaría Flecha @ 2019-10-26 14:15 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: cilizili@protonmail.com; pgsql-bugs@lists.postgresql.org

On Sat, Oct 26, 2019 at 3:36 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

>
> I do not think this is a bug.  There are probably thousands of ways to
> break Postgres by misconfiguring your system, and this is one of 'em.
>
>
There is a difference in the behaviour for the WIN32 port. In other
platforms execl() is called from "src/bin/pg_ctl/pc_ctl" with the full path
("/bin/sh"), but for WIN32 the function CreateProcessAsUser() calls the CMD
command without a path, and this function has a search logic of its own [1].

If even this difference out is of any value I can propose a patch.

[1]
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createproc...

Regards,

Juan José Santamaría Flecha

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
  2019-10-26 04:30 BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. PG Bug reporting form <noreply@postgresql.org>
  2019-10-26 13:36 ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 14:15   ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
@ 2019-10-26 15:20     ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 17:33       ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Tom Lane @ 2019-10-26 15:20 UTC (permalink / raw)
  To: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>; +Cc: cilizili@protonmail.com; pgsql-bugs@lists.postgresql.org

=?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= <juanjo.santamaria@gmail.com> writes:
> There is a difference in the behaviour for the WIN32 port. In other
> platforms execl() is called from "src/bin/pg_ctl/pc_ctl" with the full path
> ("/bin/sh"), but for WIN32 the function CreateProcessAsUser() calls the CMD
> command without a path, and this function has a search logic of its own [1].

Right, but does cmd.exe have a well-defined location in Windows?
I don't think we can know which drive it's on, for starters.

Ultimately this seems like a problem of insecure search path,
which is not our responsibility to fix (and people would not
appreciate us trying, in many cases).

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
  2019-10-26 04:30 BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. PG Bug reporting form <noreply@postgresql.org>
  2019-10-26 13:36 ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 14:15   ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 15:20     ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-10-26 17:33       ` Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 17:44         ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 10+ messages in thread

From: Juan José Santamaría Flecha @ 2019-10-26 17:33 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: cilizili@protonmail.com; pgsql-bugs@lists.postgresql.org

On Sat, Oct 26, 2019 at 5:20 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

>
> Right, but does cmd.exe have a well-defined location in Windows?
> I don't think we can know which drive it's on, for starters.
>
>
The environment variable COMSPEC [1] should point to the right location.


> Ultimately this seems like a problem of insecure search path,
> which is not our responsibility to fix (and people would not
> appreciate us trying, in many cases).
>
>
Totally agree, if this not is an improvement there is nothing to fix.

[1] https://en.wikipedia.org/wiki/COMSPEC

Regards,

Juan José Santamaría Flecha

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
  2019-10-26 04:30 BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. PG Bug reporting form <noreply@postgresql.org>
  2019-10-26 13:36 ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 14:15   ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 15:20     ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 17:33       ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
@ 2019-10-26 17:44         ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-27 10:07           ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Tom Lane @ 2019-10-26 17:44 UTC (permalink / raw)
  To: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>; +Cc: cilizili@protonmail.com; pgsql-bugs@lists.postgresql.org

=?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= <juanjo.santamaria@gmail.com> writes:
> On Sat, Oct 26, 2019 at 5:20 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Right, but does cmd.exe have a well-defined location in Windows?
>> I don't think we can know which drive it's on, for starters.

> The environment variable COMSPEC [1] should point to the right location.

Hm.  I don't have any objection to using COMSPEC if it's set, but
of course that changes nothing from a security perspective.  It's
just a different route by which pg_ctl, pg_upgrade, etc can be
misled.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
  2019-10-26 04:30 BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. PG Bug reporting form <noreply@postgresql.org>
  2019-10-26 13:36 ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 14:15   ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 15:20     ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 17:33       ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 17:44         ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-10-27 10:07           ` Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-27 15:42             ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 10+ messages in thread

From: Juan José Santamaría Flecha @ 2019-10-27 10:07 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: cilizili@protonmail.com; pgsql-bugs@lists.postgresql.org

On Sat, Oct 26, 2019 at 7:44 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

> =?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= <
> juanjo.santamaria@gmail.com> writes:
> > On Sat, Oct 26, 2019 at 5:20 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> Right, but does cmd.exe have a well-defined location in Windows?
> >> I don't think we can know which drive it's on, for starters.
>
> > The environment variable COMSPEC [1] should point to the right location.
>
> Hm.  I don't have any objection to using COMSPEC if it's set, but
> of course that changes nothing from a security perspective.  It's
> just a different route by which pg_ctl, pg_upgrade, etc can be
> misled.
>
>
The only impact this will have is finding the CMD executable directly,
without having to rely on CreateProcessAsUser() logic.

Please find attached a patch with this simple modification.

Regards,

Juan José Santamaría Flecha

Attachments:

0001_find_cmd_using_comspec.patch (application/x-patch, 1.1K) download diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index a3fd002..a2005c1 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -513,13 +513,20 @@ start_postmaster(void) * "exec", so we don't get to find out the postmaster's PID immediately. */ PROCESS_INFORMATION pi; + char *comspec; + const char *cmd_exec = "CMD"; + + /* CMD location using COMSPEC */ + comspec = getenv("COMSPEC"); + if (comspec == NULL) + comspec = cmd_exec; if (log_file != NULL) - snprintf(cmd, MAXPGPATH, "CMD /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"", - exec_path, pgdata_opt, post_opts, DEVNULL, log_file); + snprintf(cmd, MAXPGPATH, "\"%s\" /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"", + comspec, exec_path, pgdata_opt, post_opts, DEVNULL, log_file); else - snprintf(cmd, MAXPGPATH, "CMD /C \"\"%s\" %s%s < \"%s\" 2>&1\"", - exec_path, pgdata_opt, post_opts, DEVNULL); + snprintf(cmd, MAXPGPATH, "\"%s\" /C \"\"%s\" %s%s < \"%s\" 2>&1\"", + comspec, exec_path, pgdata_opt, post_opts, DEVNULL); if (!CreateRestrictedProcess(cmd, &pi, false)) {
^ permalink raw reply [nested|flat] 10+ messages in thread

* Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
  2019-10-26 04:30 BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. PG Bug reporting form <noreply@postgresql.org>
  2019-10-26 13:36 ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 14:15   ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 15:20     ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 17:33       ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 17:44         ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-27 10:07           ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
@ 2019-10-27 15:42             ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-27 20:55               ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Tom Lane @ 2019-10-27 15:42 UTC (permalink / raw)
  To: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>; +Cc: cilizili@protonmail.com; pgsql-bugs@lists.postgresql.org

=?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= <juanjo.santamaria@gmail.com> writes:
> On Sat, Oct 26, 2019 at 7:44 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Hm.  I don't have any objection to using COMSPEC if it's set, but
>> of course that changes nothing from a security perspective.  It's
>> just a different route by which pg_ctl, pg_upgrade, etc can be
>> misled.

> Please find attached a patch with this simple modification.

I poked around a bit for other references to cmd.exe.  It looks
like psql's do_shell() is handling this correctly already, but should
we not also fix spawn_process() in src/test/regress/pg_regress.c ?

There are also a couple of references in pg_upgrade's test.sh,
but I don't feel a need to change those.

Another point that could be raised here: seeing that psql honors the
SHELL variable to substitute for /bin/sh, should these other programs
do likewise?  I'm inclined to think not, because what psql is doing is
launching an interactive shell, so the user's shell preference should be
honored.  In these other cases we want plain old Bourne shell thank you,
so ignoring SHELL seems correct.  But it's worth thinking about, and
perhaps adding a comment about.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
  2019-10-26 04:30 BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. PG Bug reporting form <noreply@postgresql.org>
  2019-10-26 13:36 ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 14:15   ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 15:20     ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 17:33       ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 17:44         ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-27 10:07           ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-27 15:42             ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-10-27 20:55               ` Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-28 18:16                 ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 10+ messages in thread

From: Juan José Santamaría Flecha @ 2019-10-27 20:55 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: cilizili@protonmail.com; pgsql-bugs@lists.postgresql.org

On Sun, Oct 27, 2019 at 4:42 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

> =?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= <
> juanjo.santamaria@gmail.com> writes:
> > On Sat, Oct 26, 2019 at 7:44 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> Hm.  I don't have any objection to using COMSPEC if it's set, but
> >> of course that changes nothing from a security perspective.  It's
> >> just a different route by which pg_ctl, pg_upgrade, etc can be
> >> misled.
>
> > Please find attached a patch with this simple modification.
>
> I poked around a bit for other references to cmd.exe.  It looks
> like psql's do_shell() is handling this correctly already, but should
> we not also fix spawn_process() in src/test/regress/pg_regress.c ?
>
>
Agreed, so please find attached an updated patch.


> There are also a couple of references in pg_upgrade's test.sh,
> but I don't feel a need to change those.
>
>
Agreed, this will honor PATH since is called from a shell,


> Another point that could be raised here: seeing that psql honors the
> SHELL variable to substitute for /bin/sh, should these other programs
> do likewise?  I'm inclined to think not, because what psql is doing is
> launching an interactive shell, so the user's shell preference should be
> honored.  In these other cases we want plain old Bourne shell thank you,
> so ignoring SHELL seems correct.  But it's worth thinking about, and
> perhaps adding a comment about.
>
>
Also agree on this: honoring SHELL makes sense only if there is client
interaction.

Regards,

Juan José Santamaría Flecha

Attachments:

0001_find_cmd_using_comspec_v2.patch (application/octet-stream, 1.8K) download diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index a3fd002..a2005c1 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -513,13 +513,20 @@ start_postmaster(void) * "exec", so we don't get to find out the postmaster's PID immediately. */ PROCESS_INFORMATION pi; + char *comspec; + const char *cmd_exec = "CMD"; + + /* CMD location using COMSPEC */ + comspec = getenv("COMSPEC"); + if (comspec == NULL) + comspec = cmd_exec; if (log_file != NULL) - snprintf(cmd, MAXPGPATH, "CMD /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"", - exec_path, pgdata_opt, post_opts, DEVNULL, log_file); + snprintf(cmd, MAXPGPATH, "\"%s\" /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"", + comspec, exec_path, pgdata_opt, post_opts, DEVNULL, log_file); else - snprintf(cmd, MAXPGPATH, "CMD /C \"\"%s\" %s%s < \"%s\" 2>&1\"", - exec_path, pgdata_opt, post_opts, DEVNULL); + snprintf(cmd, MAXPGPATH, "\"%s\" /C \"\"%s\" %s%s < \"%s\" 2>&1\"", + comspec, exec_path, pgdata_opt, post_opts, DEVNULL); if (!CreateRestrictedProcess(cmd, &pi, false)) { diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index 6554ce2..44797a2 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -1193,9 +1193,16 @@ spawn_process(const char *cmdline) PROCESS_INFORMATION pi; char *cmdline2; HANDLE restrictedToken; + char *comspec; + const char *cmd_exec = "CMD"; + + /* CMD location using COMSPEC */ + comspec = getenv("COMSPEC"); + if (comspec == NULL) + comspec = cmd_exec; memset(&pi, 0, sizeof(pi)); - cmdline2 = psprintf("cmd /c \"%s\"", cmdline); + cmdline2 = psprintf("\"%s\" /c \"%s\"", comspec, cmdline); if ((restrictedToken = CreateRestrictedProcess(cmdline2, &pi)) == 0)
^ permalink raw reply [nested|flat] 10+ messages in thread

* Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory.
  2019-10-26 04:30 BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. PG Bug reporting form <noreply@postgresql.org>
  2019-10-26 13:36 ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 14:15   ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 15:20     ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-26 17:33       ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-26 17:44         ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-27 10:07           ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
  2019-10-27 15:42             ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Tom Lane <tgl@sss.pgh.pa.us>
  2019-10-27 20:55               ` Re: BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
@ 2019-10-28 18:16                 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2019-10-28 18:16 UTC (permalink / raw)
  To: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>; +Cc: cilizili@protonmail.com; pgsql-bugs@lists.postgresql.org

=?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= <juanjo.santamaria@gmail.com> writes:
> On Sun, Oct 27, 2019 at 4:42 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I poked around a bit for other references to cmd.exe.  It looks
>> like psql's do_shell() is handling this correctly already, but should
>> we not also fix spawn_process() in src/test/regress/pg_regress.c ?

> Agreed, so please find attached an updated patch.

Looks OK now, so pushed.  (I don't have the ability to test this
locally, but the buildfarm will soon tell us if it's wrong.)

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2019-10-28 18:16 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-10-26 04:30 BUG #16080: pg_ctl is failed if a fake cmd.exe exist in the current directory. PG Bug reporting form <noreply@postgresql.org>
2019-10-26 13:36 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-10-26 14:15   ` Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
2019-10-26 15:20     ` Tom Lane <tgl@sss.pgh.pa.us>
2019-10-26 17:33       ` Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
2019-10-26 17:44         ` Tom Lane <tgl@sss.pgh.pa.us>
2019-10-27 10:07           ` Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
2019-10-27 15:42             ` Tom Lane <tgl@sss.pgh.pa.us>
2019-10-27 20:55               ` Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
2019-10-28 18:16                 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox