From 32f628be74d8ab43423ca7913b81f7eb21b312d4 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 28 May 2015 12:17:22 -0400 Subject: 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 --- src/backend/utils/adt/misc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/backend/utils/adt/misc.c') diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index de68cdddf1d..c0495d955ce 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -374,11 +374,13 @@ pg_tablespace_location(PG_FUNCTION_ARGS) rllen = readlink(sourcepath, targetpath, sizeof(targetpath)); if (rllen < 0) ereport(ERROR, - (errmsg("could not read symbolic link \"%s\": %m", + (errcode_for_file_access(), + errmsg("could not read symbolic link \"%s\": %m", sourcepath))); - else if (rllen >= sizeof(targetpath)) + if (rllen >= sizeof(targetpath)) ereport(ERROR, - (errmsg("symbolic link \"%s\" target is too long", + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("symbolic link \"%s\" target is too long", sourcepath))); targetpath[rllen] = '\0'; -- cgit v1.2.3