diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-12-07 13:34:13 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-12-07 13:34:13 -0500 |
commit | 0d0ec527afec5e7bc9d709c40a37f295b627336a (patch) | |
tree | 3c615116b3437527398629c30a712248070fa2e0 /src/backend/utils/adt/misc.c | |
parent | 0d9b09282fbf2a21160d57d2f11785cb23841909 (diff) | |
download | postgresql-0d0ec527afec5e7bc9d709c40a37f295b627336a.tar.gz postgresql-0d0ec527afec5e7bc9d709c40a37f295b627336a.zip |
Fix corner cases in readlink() usage.
Make sure all calls are protected by HAVE_READLINK, and get the buffer
overflow tests right. Be a bit more paranoid about string length in
_tarWriteHeader(), too.
Diffstat (limited to 'src/backend/utils/adt/misc.c')
-rw-r--r-- | src/backend/utils/adt/misc.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 478f203273f..7a2e0c8e622 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -274,7 +274,7 @@ pg_tablespace_location(PG_FUNCTION_ARGS) int rllen; /* - * Return empty string for our two default tablespace + * Return empty string for our default tablespaces */ if (tablespaceOid == DEFAULTTABLESPACE_OID || tablespaceOid == GLOBALTABLESPACE_OID) @@ -286,13 +286,16 @@ pg_tablespace_location(PG_FUNCTION_ARGS) * in pg_tblspc/<oid>. */ snprintf(sourcepath, sizeof(sourcepath), "pg_tblspc/%u", tablespaceOid); - rllen =readlink(sourcepath, targetpath, sizeof(targetpath)); + + rllen = readlink(sourcepath, targetpath, sizeof(targetpath)); if (rllen < 0) ereport(ERROR, - (errmsg("could not read symbolic link \"%s\": %m", sourcepath))); + (errmsg("could not read symbolic link \"%s\": %m", + sourcepath))); else if (rllen >= sizeof(targetpath)) ereport(ERROR, - (errmsg("symbolic link \"%s\" target is too long", sourcepath))); + (errmsg("symbolic link \"%s\" target is too long", + sourcepath))); targetpath[rllen] = '\0'; PG_RETURN_TEXT_P(cstring_to_text(targetpath)); @@ -300,6 +303,7 @@ pg_tablespace_location(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("tablespaces are not supported on this platform"))); + PG_RETURN_NULL(); #endif } |