Re: BUG #18971: Server passes an invalid (indirect) path in PGDATA to the external program

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Dmitry Kovalenko <d(dot)kovalenko(at)postgrespro(dot)ru>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18971: Server passes an invalid (indirect) path in PGDATA to the external program
Date: 2025-06-29 06:00:11
Message-ID: ec7252885b989f6794a7407660a660aa6c385fd7.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sat, 2025-06-28 at 14:12 -0700, David G. Johnston wrote:
> On Sat, Jun 28, 2025 at 1:19 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > I'm not sure which part of "don't rely on PGDATA" you didn't get.
> > Under normal circumstances, Postgres itself doesn't set that at all.
>
> If we have to tell someone to not rely on a value that we've set we've
> done something wrong.

I am not sure that that is an accurate description. Look at the code
in pg_ctl.c:

/* process command-line options */
while ((c = getopt_long(argc, argv, "cD:e:l:m:N:o:p:P:sS:t:U:wW",
long_options, &option_index)) != -1)
{
switch (c)
{
case 'D':
{
char *pgdata_D;

pgdata_D = pg_strdup(optarg);
canonicalize_path(pgdata_D);
setenv("PGDATA", pgdata_D, 1);

/*
* We could pass PGDATA just in an environment variable
* but we do -D too for clearer postmaster 'ps' display
*/
pgdata_opt = psprintf("-D \"%s\" ", pgdata_D);
free(pgdata_D);
break;
}

So we take the value specified with the -D option, canonicalize_path() it
and set it in the environment. canonicalize_path() does the following:

/*
* canonicalize_path()
*
* Clean up path by:
* o make Win32 path use Unix slashes
* o remove trailing quote on Win32
* o remove trailing slash
* o remove duplicate (adjacent) separators
* o remove '.' (unless path reduces to only '.')
* o process '..' ourselves, removing it if possible
* Modifies path in-place.

So, essentially, Dmitry feeds a weird path to the -D option and then
complains that PGDATA is set to a weird value.

Yours,
Laurenz Albe

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-06-29 17:01:53 Re: BUG #18970: Atempt to alter type of table column used in row type with check leads to assertion failure
Previous Message jian he 2025-06-29 05:28:05 Re: BUG #18970: Atempt to alter type of table column used in row type with check leads to assertion failure