aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-03-17 16:18:46 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-03-17 16:18:46 -0400
commit8620a7f6dbdf978e57cdb9f42802a0418656d863 (patch)
treed37d880cdf12c50efe29640b4be3161168e45b0b /src/include
parenta50e4fd028a1ece2b1a04df2c9ae6581783e9eef (diff)
downloadpostgresql-8620a7f6dbdf978e57cdb9f42802a0418656d863.tar.gz
postgresql-8620a7f6dbdf978e57cdb9f42802a0418656d863.zip
Code review for server's handling of "tablespace map" files.
While looking at Robert Foggia's report, I noticed a passel of other issues in the same area: * The scheme for backslash-quoting newlines in pathnames is just wrong; it will misbehave if the last ordinary character in a pathname is a backslash. I'm not sure why we're bothering to allow newlines in tablespace paths, but if we're going to do it we should do it without introducing other problems. Hence, backslashes themselves have to be backslashed too. * The author hadn't read the sscanf man page very carefully, because this code would drop any leading whitespace from the path. (I doubt that a tablespace path with leading whitespace could happen in practice; but if we're bothering to allow newlines in the path, it sure seems like leading whitespace is little less implausible.) Using sscanf for the task of finding the first space is overkill anyway. * While I'm not 100% sure what the rationale for escaping both \r and \n is, if the idea is to allow Windows newlines in the file then this code failed, because it'd throw an error if it saw \r followed by \n. * There's no cross-check for an incomplete final line in the map file, which would be a likely apparent symptom of the improper-escaping bug. On the generation end, aside from the escaping issue we have: * If needtblspcmapfile is true then do_pg_start_backup will pass back escaped strings in tablespaceinfo->path values, which no caller wants or is prepared to deal with. I'm not sure if there's a live bug from that, but it looks like there might be (given the dubious assumption that anyone actually has newlines in their tablespace paths). * It's not being very paranoid about the possibility of random stuff in the pg_tblspc directory. IMO we should ignore anything without an OID-like name. The escaping rule change doesn't seem back-patchable: it'll require doubling of backslashes in the tablespace_map file, which is basically a basebackup format change. The odds of that causing trouble are considerably more than the odds of the existing bug causing trouble. The rest of this seems somewhat unlikely to cause problems too, so no back-patch.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/xlog.h3
-rw-r--r--src/include/replication/basebackup.h14
2 files changed, 11 insertions, 6 deletions
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 6d384d3ce6d..77187c12beb 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -384,8 +384,7 @@ typedef enum SessionBackupState
extern XLogRecPtr do_pg_start_backup(const char *backupidstr, bool fast,
TimeLineID *starttli_p, StringInfo labelfile,
- List **tablespaces, StringInfo tblspcmapfile,
- bool needtblspcmapfile);
+ List **tablespaces, StringInfo tblspcmapfile);
extern XLogRecPtr do_pg_stop_backup(char *labelfile, bool waitforarchive,
TimeLineID *stoptli_p);
extern void do_pg_abort_backup(int code, Datum arg);
diff --git a/src/include/replication/basebackup.h b/src/include/replication/basebackup.h
index cdfe4b5e19d..379eb418674 100644
--- a/src/include/replication/basebackup.h
+++ b/src/include/replication/basebackup.h
@@ -20,12 +20,18 @@
#define MAX_RATE_LOWER 32
#define MAX_RATE_UPPER 1048576
+/*
+ * Information about a tablespace
+ *
+ * In some usages, "path" can be NULL to denote the PGDATA directory itself.
+ */
typedef struct
{
- char *oid;
- char *path;
- char *rpath; /* relative path within PGDATA, or NULL */
- int64 size;
+ char *oid; /* tablespace's OID, as a decimal string */
+ char *path; /* full path to tablespace's directory */
+ char *rpath; /* relative path if it's within PGDATA, else
+ * NULL */
+ int64 size; /* total size as sent; -1 if not known */
} tablespaceinfo;
extern void SendBaseBackup(BaseBackupCmd *cmd);