1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

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.
This commit is contained in:
Tom Lane
2011-12-07 13:34:13 -05:00
parent 0d9b09282f
commit 0d0ec527af
2 changed files with 46 additions and 18 deletions

View File

@ -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
}