On 2020-01-06 21:00, Magnus Hagander wrote:
+0.5 to avoid calling OidInputFunctionCall()
Or just directly using atol() instead of atoi()? Well maybe not
directly but in a small wrapper that verifies it's not bigger than an
unsigned?
Unlike in cases where we use oidin etc, we are dealing with data that
is "mostly trusted" here, aren't we? Meaning we could call atol() on
it, and throw an error if it overflows, and be done with it?
Subdirectories in the data directory aren't exactly "untrusted enduser
data"...
Yeah, it looks like we are using strtoul() without additional error
checking in similar situations, so here is a patch doing it like that.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From 8a4d22b95bb9f54e6834bc5285c4d84582e6f128 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Sat, 11 Jan 2020 08:16:21 +0100
Subject: [PATCH v2] Fix base backup with database OIDs larger than INT32_MAX
The use of pg_atoi() for parsing a string into an Oid fails for values
larger than INT32_MAX, since OIDs are unsigned. Instead, use plain
strtoul(). While this has less error checking, the content of the
data directory are expected to be trustworthy, so we don't need to go
out of our way to do full error checking.
Discussion:
https://www.postgresql.org/message-id/flat/dea47fc8-6c89-a2b1-07e3-754ff1ab094b%402ndquadrant.com
---
src/backend/replication/basebackup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/backend/replication/basebackup.c
b/src/backend/replication/basebackup.c
index a73893237a..ae535a0565 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -1316,7 +1316,7 @@ sendDir(const char *path, int basepathlen, bool sizeonly,
List *tablespaces,
if (!sizeonly)
sent = sendFile(pathbuf, pathbuf + basepathlen
+ 1, &statbuf,
- true, isDbDir ?
pg_atoi(lastDir + 1, sizeof(Oid), 0) : InvalidOid);
+ true, isDbDir ?
(Oid) strtoul(lastDir + 1, NULL, 10) : InvalidOid);
if (sent || sizeonly)
{
--
2.24.1