pg_ctl: Disable autoruns for cmd.exe on Windows
authorMichael Paquier <[email protected]>
Fri, 12 Jan 2024 04:53:12 +0000 (13:53 +0900)
committerMichael Paquier <[email protected]>
Fri, 12 Jan 2024 04:53:12 +0000 (13:53 +0900)
On Windows, cmd.exe is used to launch the postmaster process to ease its
redirection setup.  However, cmd.exe may execute other programs at
startup due to autorun configurations, which could influence the
postmaster startup.  This patch adds /D flag to the launcher cmd.exe
command line to disable autorun settings written in the registry.

This was originally applied on HEAD as of 9886744a361b without a
backpatch, but the patch has survived CI and buildfarm cycles.  I have
checked that cmd /d exists down to Windows XP, which should make this
change work correctly in the oldest branches still supported.

Reported-by: Hayato Kuroda
Author: Kyotaro Horiguchi
Reviewed-by: Robert Haas, Michael Paquier
Discussion: https://postgr.es/m/20230922.161551.320043332510268554[email protected]
Backpatch-through: 12

src/bin/pg_ctl/pg_ctl.c

index 552e3a6a1c8f76950c915034b2c437ea55128e0d..f9e0ee4eeef4918853a6617b9d8eba12e58fbe7f 100644 (file)
@@ -559,11 +559,11 @@ start_postmaster(void)
        else
            close(fd);
 
-       cmd = psprintf("\"%s\" /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"",
+       cmd = psprintf("\"%s\" /D /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"",
                       comspec, exec_path, pgdata_opt, post_opts, DEVNULL, log_file);
    }
    else
-       cmd = psprintf("\"%s\" /C \"\"%s\" %s%s < \"%s\" 2>&1\"",
+       cmd = psprintf("\"%s\" /D /C \"\"%s\" %s%s < \"%s\" 2>&1\"",
                       comspec, exec_path, pgdata_opt, post_opts, DEVNULL);
 
    if (!CreateRestrictedProcess(cmd, &pi, false))