Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f1c674

Browse files
macdiceadunstan
authored andcommitted
Fix stat() for recursive junction points on Windows.
Commitc5cb8f3 supposed that we'd only ever have to follow one junctionpoint in stat(), because we don't construct longer chains of them ourselves.When examining a parent directory supplied by the user, we should really beable to cope with longer chains, just in case someone has their systemset up that way. Choose an arbitrary cap of 8, to match the minimumacceptable value of SYMLOOP_MAX in POSIX.Previously I'd avoided reporting ELOOP thinking Windows didn't have it,but it turns out that it does, so we can use the proper error number.Reviewed-by: Roman Zharkov <r.zharkov@postgrespro.ru>Discussion:https://postgr.es/m/CA%2BhUKGJ7JDGWYFt9%3D-TyJiRRy5q9TtPfqeKkneWDr1XPU1%2Biqw%40mail.gmail.comDiscussion:https://postgr.es/m/CA%2BhUKG%2BajSQ_8eu2AogTncOnZ5me2D-Cn66iN_-wZnRjLN%2Bicg%40mail.gmail.comBackpatched commit4517358 as above by Thomas Munro into releases 13 thru 15Discussion:https://postgr.es/m/CA+hUKGLbnv+pe3q1fYOVkLD3pMra7GuihfMxUN-1831YH9RYQg@mail.gmail.com
1 parent060f9f5 commit9f1c674

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

‎src/port/win32stat.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,33 @@ _pglstat64(const char *name, struct stat *buf)
201201
int
202202
_pgstat64(constchar*name,structstat*buf)
203203
{
204+
intloops=0;
204205
intret;
206+
charcurr[MAXPGPATH];
205207

206208
ret=_pglstat64(name,buf);
207209

210+
strlcpy(curr,name,MAXPGPATH);
211+
208212
/* Do we need to follow a symlink (junction point)? */
209-
if (ret==0&&S_ISLNK(buf->st_mode))
213+
while (ret==0&&S_ISLNK(buf->st_mode))
210214
{
211215
charnext[MAXPGPATH];
212216
ssize_tsize;
213217

218+
if (++loops>8)
219+
{
220+
errno=ELOOP;
221+
return-1;
222+
}
223+
214224
/*
215225
* _pglstat64() already called readlink() once to be able to fill in
216226
* st_size, and now we need to do it again to get the path to follow.
217227
* That could be optimized, but stat() on symlinks is probably rare
218228
* and this way is simple.
219229
*/
220-
size=readlink(name,next,sizeof(next));
230+
size=readlink(curr,next,sizeof(next));
221231
if (size<0)
222232
{
223233
if (errno==EACCES&&
@@ -236,17 +246,7 @@ _pgstat64(const char *name, struct stat *buf)
236246
next[size]=0;
237247

238248
ret=_pglstat64(next,buf);
239-
if (ret==0&&S_ISLNK(buf->st_mode))
240-
{
241-
/*
242-
* We're only prepared to go one hop, because we only expect to
243-
* deal with the simple cases that we create. The error for too
244-
* many symlinks is supposed to be ELOOP, but Windows hasn't got
245-
* it.
246-
*/
247-
errno=EIO;
248-
return-1;
249-
}
249+
strcpy(curr,next);
250250
}
251251

252252
returnret;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp