summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-03-17 16:10:38 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-03-17 16:10:38 -0400
commit2a4c9fd9c77041fc7207c268eaf0155d11f100a2 (patch)
tree798a2bef7f6a1fe7eb744013eae79cbf69ba023a
parent7ce7f2b79890ea1465c654fd0ee5271bcd01b716 (diff)
Prevent buffer overrun in read_tablespace_map().
Robert Foggia of Trustwave reported that read_tablespace_map() fails to prevent an overrun of its on-stack input buffer. Since the tablespace map file is presumed trustworthy, this does not seem like an interesting security vulnerability, but still we should fix it just in the name of robustness. While here, document that pg_basebackup's --tablespace-mapping option doesn't work with tar-format output, because it doesn't. To make it work, we'd have to modify the tablespace_map file within the tarball sent by the server, which might be possible but I'm not volunteering. (Less-painful solutions would require changing the basebackup protocol so that the source server could adjust the map. That's not very appetizing either.)
-rw-r--r--doc/src/sgml/ref/pg_basebackup.sgml10
-rw-r--r--src/backend/access/transam/xlog.c2
2 files changed, 9 insertions, 3 deletions
diff --git a/doc/src/sgml/ref/pg_basebackup.sgml b/doc/src/sgml/ref/pg_basebackup.sgml
index 2b7443b93fd..40d92960edb 100644
--- a/doc/src/sgml/ref/pg_basebackup.sgml
+++ b/doc/src/sgml/ref/pg_basebackup.sgml
@@ -155,7 +155,8 @@ PostgreSQL documentation
the target directory. If the cluster contains additional
tablespaces, the main data directory will be placed in the
target directory, but all other tablespaces will be placed
- in the same absolute path as they have on the server.
+ in the same absolute path as they have on the source server.
+ (See <option>--tablespace-mapping</option> to change that.)
</para>
<para>
This is the default format.
@@ -291,7 +292,12 @@ PostgreSQL documentation
the main data directory are updated to point to the new location. So
the new data directory is ready to be used for a new server instance
with all tablespaces in the updated locations.
- </para>
+ </para>
+
+ <para>
+ Currently, this option only works with plain output format; it is
+ ignored if tar format is selected.
+ </para>
</listitem>
</varlistentry>
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index ba2fbdcf02a..126ea6521ee 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -11517,7 +11517,7 @@ read_tablespace_map(List **tablespaces)
}
else if ((ch == '\n' || ch == '\r') && prev_ch == '\\')
str[i - 1] = ch;
- else
+ else if (i < sizeof(str) - 1)
str[i++] = ch;
prev_ch = ch;
}