From: wangsh.fnst@fujitsu.com <wangsh.fnst@fujitsu.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: drop tablespace failed when location contains .. on win32
Date: Wed, 8 Sep 2021 10:16:46 +0000
Message-ID: <OSBPR01MB4214FA221FFE046F11F2AD74F2D49@OSBPR01MB4214.jpnprd01.prod.outlook.com> (raw)
Hi,
I find a problem related to tablespace on win32(server2019).
> postgres=# create tablespace tbs location 'C:\Users\postgres\postgres_install\aa\..\aa';
> CREATE TABLESPACE
> postgres=# create table tbl(col int) tablespace tbs;
> ERROR: could not stat directory "pg_tblspc/16384/PG_15_202109061/12754": Invalid argument
> postgres=# drop tablespace tbs;
> WARNING: could not open directory "pg_tblspc/16384/PG_15_202109061": No such file or directory
> ERROR: could not stat file "pg_tblspc/16384": Invalid argument
I find that canonicalize_path() only remove the trailing '..', in this case, '..' is not removed , and
pgsymlink succeed.
But, in fact, if I double click the dir (%PGDATA%\pg_tblspac\16387), the error message is shown:
> The filename, directory name, or volume label syntax is incorrect.
Since the pgsymlink() seems right and I'm not sure I can change the action of canonicalize_path,
so I want to add a error check(patch is attached).
Any comment ?
Regards,
Shenhao Wang
Attachments:problem.diff (application/octet-stream, 1.2K) downloaddiff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.cindex 932e7ae37b..c1b047b8e9 100644--- a/src/backend/commands/tablespace.c+++ b/src/backend/commands/tablespace.c@@ -269,20 +269,27 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
/*
* Allowing relative paths seems risky
*
* this also helps us ensure that location is not empty or whitespace
*/
if (!is_absolute_path(location))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("tablespace location must be an absolute path")));
+#if WIN32+ if (path_contains_parent_reference(location))+ ereport(ERROR,+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),+ errmsg("tablespace location cannot contain \"..\"")));+#endif+
/*
* Check that location isn't too long. Remember that we're going to append
* 'PG_XXX/<dboid>/<relid>_<fork>.<nnn>'. FYI, we never actually
* reference the whole path here, but MakePGDirectory() uses the first two
* parts.
*/
if (strlen(location) + 1 + strlen(TABLESPACE_VERSION_DIRECTORY) + 1 +
OIDCHARS + 1 + OIDCHARS + 1 + FORKNAMECHARS + 1 + OIDCHARS > MAXPGPATH)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: wangsh.fnst@fujitsu.com
Subject: Re: drop tablespace failed when location contains .. on win32
In-Reply-To: <OSBPR01MB4214FA221FFE046F11F2AD74F2D49@OSBPR01MB4214.jpnprd01.prod.outlook.com>
References: <OSBPR01MB4214FA221FFE046F11F2AD74F2D49@OSBPR01MB4214.jpnprd01.prod.outlook.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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