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

Commit32f628b

Browse files
committed
Fix assorted inconsistencies in our calls of readlink().
Ensure that we null-terminate the result string (one place in pg_rewind).Be paranoid about out-of-range results from readlink() (should not happen,but there is no good reason for some call sites to be careful about it andothers not). Consistently use the whole buffer, not sometimes one byteless. Ensure we emit an appropriate errcode() in all cases. Spell theerror messages the same way.The only serious bug here is the missing null-termination in pg_rewind,which is new code, so no need for a back-patch.Abhijit Menon-Sen and Tom Lane
1 parentf46edf4 commit32f628b

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

‎src/backend/replication/basebackup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,8 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
10281028
pathbuf)));
10291029
if (rllen >=sizeof(linkpath))
10301030
ereport(ERROR,
1031-
(errmsg("symbolic link \"%s\" target is too long",
1031+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1032+
errmsg("symbolic link \"%s\" target is too long",
10321033
pathbuf)));
10331034
linkpath[rllen]='\0';
10341035

‎src/backend/storage/file/fd.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,18 +2517,17 @@ walkdir(char *path, void (*action) (char *fname, bool isdir))
25172517
intlen;
25182518
structstatlst;
25192519

2520-
len=readlink(subpath,linkpath,sizeof(linkpath)-1);
2520+
len=readlink(subpath,linkpath,sizeof(linkpath));
25212521
if (len<0)
25222522
ereport(ERROR,
25232523
(errcode_for_file_access(),
25242524
errmsg("could not read symbolic link \"%s\": %m",
25252525
subpath)));
2526-
2527-
if (len >=sizeof(linkpath)-1)
2526+
if (len >=sizeof(linkpath))
25282527
ereport(ERROR,
2529-
(errmsg("symbolic link \"%s\" target is too long",
2528+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2529+
errmsg("symbolic link \"%s\" target is too long",
25302530
subpath)));
2531-
25322531
linkpath[len]='\0';
25332532

25342533
if (lstat(linkpath,&lst)==0)

‎src/backend/utils/adt/misc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,13 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
374374
rllen=readlink(sourcepath,targetpath,sizeof(targetpath));
375375
if (rllen<0)
376376
ereport(ERROR,
377-
(errmsg("could not read symbolic link \"%s\": %m",
377+
(errcode_for_file_access(),
378+
errmsg("could not read symbolic link \"%s\": %m",
378379
sourcepath)));
379-
elseif (rllen >=sizeof(targetpath))
380+
if (rllen >=sizeof(targetpath))
380381
ereport(ERROR,
381-
(errmsg("symbolic link \"%s\" target is too long",
382+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
383+
errmsg("symbolic link \"%s\" target is too long",
382384
sourcepath)));
383385
targetpath[rllen]='\0';
384386

‎src/bin/pg_rewind/copy_fetch.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,16 @@ recurse_dir(const char *datadir, const char *parentpath,
112112
{
113113
#if defined(HAVE_READLINK)|| defined(WIN32)
114114
charlink_target[MAXPGPATH];
115-
ssize_tlen;
115+
intlen;
116116

117-
len=readlink(fullpath,link_target,sizeof(link_target)-1);
118-
if (len==-1)
119-
pg_fatal("readlink() failed on \"%s\": %s\n",
117+
len=readlink(fullpath,link_target,sizeof(link_target));
118+
if (len<0)
119+
pg_fatal("could not read symbolic link \"%s\": %s\n",
120120
fullpath,strerror(errno));
121-
122-
if (len==sizeof(link_target)-1)
123-
{
124-
/* path was truncated */
125-
pg_fatal("symbolic link \"%s\" target path too long\n",
121+
if (len >=sizeof(link_target))
122+
pg_fatal("symbolic link \"%s\" target is too long\n",
126123
fullpath);
127-
}
124+
link_target[len]='\0';
128125

129126
callback(path,FILE_TYPE_SYMLINK,0,link_target);
130127

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp