Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f71007f

Browse files
committed
Fix readlink() for non-PostgreSQL junction points on Windows.
Since commit c5cb8f3 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
1 parent 387803d commit f71007f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/port/dirmod.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,21 @@ pgreadlink(const char *path, char *buf, size_t size)
363363
r -= 1;
364364

365365
/*
366-
* If the path starts with "\??\", which it will do in most (all?) cases,
367-
* strip those out.
366+
* If the path starts with "\??\" followed by a "drive absolute" path
367+
* (known to Windows APIs as RtlPathTypeDriveAbsolute), then strip that
368+
* prefix. This undoes some of the transformation performed by
369+
* pqsymlink(), to get back to a format that users are used to seeing. We
370+
* don't know how to transform other path types that might be encountered
371+
* outside PGDATA, so we just return them directly.
368372
*/
369-
if (r > 4 && strncmp(buf, "\\??\\", 4) == 0)
373+
if (r >= 7 &&
374+
buf[0] == '\\' &&
375+
buf[1] == '?' &&
376+
buf[2] == '?' &&
377+
buf[3] == '\\' &&
378+
isalpha(buf[4]) &&
379+
buf[5] == ':' &&
380+
buf[6] == '\\')
370381
{
371382
memmove(buf, buf + 4, strlen(buf + 4) + 1);
372383
r -= 4;

0 commit comments

Comments
 (0)