Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 939d10c

Browse files
committed
Guard against null arguments in binary_upgrade_create_empty_extension().
The CHECK_IS_BINARY_UPGRADE macro is not sufficient security protection if we're going to dereference pass-by-reference arguments before it. But in any case we really need to explicitly check PG_ARGISNULL for all the arguments of a non-strict function, not only the ones we expect null values for. Oversight in commits 30982be and f92fc4c. Found by Andreas Seltenreich. (The other usages in pg_upgrade_support.c seem safe.)
1 parent c6aeba3 commit 939d10c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/backend/utils/adt/pg_upgrade_support.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,28 @@ binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS)
129129
Datum
130130
binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
131131
{
132-
text *extName = PG_GETARG_TEXT_PP(0);
133-
text *schemaName = PG_GETARG_TEXT_PP(1);
134-
bool relocatable = PG_GETARG_BOOL(2);
135-
text *extVersion = PG_GETARG_TEXT_PP(3);
132+
text *extName;
133+
text *schemaName;
134+
bool relocatable;
135+
text *extVersion;
136136
Datum extConfig;
137137
Datum extCondition;
138138
List *requiredExtensions;
139139

140140
CHECK_IS_BINARY_UPGRADE;
141141

142+
/* We must check these things before dereferencing the arguments */
143+
if (PG_ARGISNULL(0) ||
144+
PG_ARGISNULL(1) ||
145+
PG_ARGISNULL(2) ||
146+
PG_ARGISNULL(3))
147+
elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
148+
149+
extName = PG_GETARG_TEXT_PP(0);
150+
schemaName = PG_GETARG_TEXT_PP(1);
151+
relocatable = PG_GETARG_BOOL(2);
152+
extVersion = PG_GETARG_TEXT_PP(3);
153+
142154
if (PG_ARGISNULL(4))
143155
extConfig = PointerGetDatum(NULL);
144156
else

0 commit comments

Comments
 (0)