summaryrefslogtreecommitdiff
path: root/src/bin/pg_rewind/copy_fetch.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-05-28 12:17:22 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2015-05-28 12:17:22 -0400
commit32f628be74d8ab43423ca7913b81f7eb21b312d4 (patch)
treede18887a837b733cac8be12996602da9ce869247 /src/bin/pg_rewind/copy_fetch.c
parentf46edf479e2468a08caca2a03ec7e258930a7161 (diff)
downloadpostgresql-32f628be74d8ab43423ca7913b81f7eb21b312d4.tar.gz
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 and others not). Consistently use the whole buffer, not sometimes one byte less. Ensure we emit an appropriate errcode() in all cases. Spell the error 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
Diffstat (limited to 'src/bin/pg_rewind/copy_fetch.c')
-rw-r--r--src/bin/pg_rewind/copy_fetch.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/bin/pg_rewind/copy_fetch.c b/src/bin/pg_rewind/copy_fetch.c
index 9e317a2c7c..c92744ca77 100644
--- a/src/bin/pg_rewind/copy_fetch.c
+++ b/src/bin/pg_rewind/copy_fetch.c
@@ -112,19 +112,16 @@ recurse_dir(const char *datadir, const char *parentpath,
{
#if defined(HAVE_READLINK) || defined(WIN32)
char link_target[MAXPGPATH];
- ssize_t len;
+ int len;
- len = readlink(fullpath, link_target, sizeof(link_target) - 1);
- if (len == -1)
- pg_fatal("readlink() failed on \"%s\": %s\n",
+ len = readlink(fullpath, link_target, sizeof(link_target));
+ if (len < 0)
+ pg_fatal("could not read symbolic link \"%s\": %s\n",
fullpath, strerror(errno));
-
- if (len == sizeof(link_target) - 1)
- {
- /* path was truncated */
- pg_fatal("symbolic link \"%s\" target path too long\n",
+ if (len >= sizeof(link_target))
+ pg_fatal("symbolic link \"%s\" target is too long\n",
fullpath);
- }
+ link_target[len] = '\0';
callback(path, FILE_TYPE_SYMLINK, 0, link_target);