diff options
author | Robert Haas <rhaas@postgresql.org> | 2023-10-23 15:17:26 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2023-10-23 15:17:26 -0400 |
commit | 5b36e8f078a3c68fd1c530c59c4ed961c15c7ab4 (patch) | |
tree | aa6dd1fdaedf83b40cac7a08e566dc6234e3801d /src/backend/access/transam/xlog.c | |
parent | 5c47c6546c413d5eb51c1626070a807026e6139d (diff) | |
download | postgresql-5b36e8f078a3c68fd1c530c59c4ed961c15c7ab4.tar.gz postgresql-5b36e8f078a3c68fd1c530c59c4ed961c15c7ab4.zip |
Change struct tablespaceinfo's oid member from 'char *' to 'Oid'
This shouldn't change behavior except in the unusual case where
there are file in the tablespace directory that have entirely
numeric names but are nevertheless not possible names for a
tablespace directory, either because their names have leading zeroes
that shouldn't be there, or the value is actually zero, or because
the value is too large to represent as an OID.
In those cases, the directory would previously have made it into
the list of tablespaceinfo objects and no longer will. Thus, base
backups will now ignore such directories, instead of treating them
as legitimate tablespace directories. Similarly, if entries for
such tablespaces occur in a tablespace_map file, they will now
be rejected as erroneous, instead of being honored.
This is infrastructure for future work that wants to be able to
know the tablespace of each relation that is part of a backup
*as an OID*. By strengthening the up-front validation, we don't
have to worry about weird cases later, and can more easily avoid
repeated string->integer conversions.
Patch by me, reviewed by David Steele.
Discussion: http://postgr.es/m/CA+TgmoZNVeBzoqDL8xvr-nkaepq815jtDR4nJzPew7=3iEuM1g@mail.gmail.com
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r-- | src/backend/access/transam/xlog.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index cea13e3d582..40461923ea3 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8579,9 +8579,22 @@ do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces, char *relpath = NULL; char *s; PGFileType de_type; + char *badp; + Oid tsoid; - /* Skip anything that doesn't look like a tablespace */ - if (strspn(de->d_name, "0123456789") != strlen(de->d_name)) + /* + * Try to parse the directory name as an unsigned integer. + * + * Tablespace directories should be positive integers that can be + * represented in 32 bits, with no leading zeroes or trailing + * garbage. If we come across a name that doesn't meet those + * criteria, skip it. + */ + if (de->d_name[0] < '1' || de->d_name[1] > '9') + continue; + errno = 0; + tsoid = strtoul(de->d_name, &badp, 10); + if (*badp != '\0' || errno == EINVAL || errno == ERANGE) continue; snprintf(fullpath, sizeof(fullpath), "pg_tblspc/%s", de->d_name); @@ -8656,7 +8669,7 @@ do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces, } ti = palloc(sizeof(tablespaceinfo)); - ti->oid = pstrdup(de->d_name); + ti->oid = tsoid; ti->path = pstrdup(linkpath); ti->rpath = relpath; ti->size = -1; |