Fix readlink() for non-PostgreSQL junction points on Windows.
authorThomas Munro <tmunro@postgresql.org>
Tue, 25 Oct 2022 02:21:42 +0000 (15:21 +1300)
committerAndrew Dunstan <andrew@dunslane.net>
Sat, 18 Jan 2025 14:33:30 +0000 (09:33 -0500)
commitf4fd5325cc870cc7563703ed2dc3661139cf5d13
tree3bf9b78e8f7e82ee3a93916ad6172ea246ab77ea
parent9f1c67488e59b9b8a1791e75783f7a817216259d
Fix readlink() for non-PostgreSQL junction points on Windows.

Since commit c5cb8f3b taught stat() to follow symlinks, and since initdb
uses pg_mkdir_p(), and that examines parent directories, our humble
readlink() implementation can now be exposed to junction points not of
PostgreSQL origin.  Those might be corrupted by our naive path mangling,
which doesn't really understand NT paths in general.

Simply decline to transform paths that don't look like a drive absolute
path.  That means that readlink() returns the NT path directly when
checking a parent directory of PGDATA that happen to point to a drive
using "rooted" format.  That  works for the purposes of our stat()
emulation.

Reported-by: Roman Zharkov <r.zharkov@postgrespro.ru>
Reviewed-by: Roman Zharkov <r.zharkov@postgrespro.ru>
Discussion: https://postgr.es/m/4590c37927d7b8ee84f9855d83229018%40postgrespro.ru
Discussion: https://postgr.es/m/CA%2BhUKG%2BajSQ_8eu2AogTncOnZ5me2D-Cn66iN_-wZnRjLN%2Bicg%40mail.gmail.com

Backpatched commit f71007fb as above by Thomas Munro into releases 13 thru 15

Discussion: https://postgr.es/m/CA+hUKGLbnv+pe3q1fYOVkLD3pMra7GuihfMxUN-1831YH9RYQg@mail.gmail.com
src/port/dirmod.c