From: Tomas Vondra Date: Sat, 29 Jul 2017 16:54:59 +0000 (+0200) Subject: Remove extra snprintf call in pg_tablespace_databases X-Git-Tag: XL_10_R1BETA1~191 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=a1b98e2c82f45fa53c949ce93a9477da2277308e;p=postgres-xl.git Remove extra snprintf call in pg_tablespace_databases The XL code did two function calls in the else branch, about like this: else /* Postgres-XC tablespaces also include node name in path */ sprintf(fctx->location, "pg_tblspc/%u/%s_%s", tablespaceOid, TABLESPACE_VERSION_DIRECTORY, PGXCNodeName); fctx->location = psprintf("pg_tblspc/%u/%s_%s", tablespaceOid, TABLESPACE_VERSION_DIRECTORY, PGXCNodeName); which is wrong, as only the first call is actually the else branch, the second call is executed unconditionally. In fact, the two calls attempt to construct the same location string, but the sprintf call assumes the 'fctx->location' string is already allocated. But it actually is not, so it's likely to cause a segfault. Fixed by removing the sprintf() call, keeping just the psprintf() one. Noticed thanks to GCC 6.3 complaining about incorrect indentation. Backpatch to XL 9.5. --- diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index b7fdf77a72..b63c5ffd04 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -401,8 +401,6 @@ pg_tablespace_databases(PG_FUNCTION_ARGS) else #ifdef PGXC /* Postgres-XC tablespaces also include node name in path */ - sprintf(fctx->location, "pg_tblspc/%u/%s_%s", tablespaceOid, - TABLESPACE_VERSION_DIRECTORY, PGXCNodeName); fctx->location = psprintf("pg_tblspc/%u/%s_%s", tablespaceOid, TABLESPACE_VERSION_DIRECTORY, PGXCNodeName);