Skip to content

Commit 5721b9b

Browse files
committed
Make object address handling more robust
pg_identify_object_as_address crashes when passed certain tuples from inconsistent system catalogs. Make it more defensive. Author: Álvaro Herrera Reviewed-by: Michaël Paquier Discussion: https://postgr.es/m/20190218202743.GA12392@alvherre.pgsql
1 parent 29d108c commit 5721b9b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3939,7 +3939,10 @@ pg_identify_object_as_address(PG_FUNCTION_ARGS)
39393939
pfree(identity);
39403940

39413941
/* object_names */
3942-
values[1] = PointerGetDatum(strlist_to_textarray(names));
3942+
if (names != NIL)
3943+
values[1] = PointerGetDatum(strlist_to_textarray(names));
3944+
else
3945+
values[1] = PointerGetDatum(construct_empty_array(TEXTOID));
39433946
nulls[1] = false;
39443947

39453948
/* object_args */
@@ -5268,10 +5271,12 @@ strlist_to_textarray(List *list)
52685271
{
52695272
ArrayType *arr;
52705273
Datum *datums;
5274+
bool *nulls;
52715275
int j = 0;
52725276
ListCell *cell;
52735277
MemoryContext memcxt;
52745278
MemoryContext oldcxt;
5279+
int lb[1];
52755280

52765281
/* Work in a temp context; easier than individually pfree'ing the Datums */
52775282
memcxt = AllocSetContextCreate(CurrentMemoryContext,
@@ -5280,18 +5285,26 @@ strlist_to_textarray(List *list)
52805285
oldcxt = MemoryContextSwitchTo(memcxt);
52815286

52825287
datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
5288+
nulls = palloc(sizeof(bool) * list_length(list));
52835289

52845290
foreach(cell, list)
52855291
{
52865292
char *name = lfirst(cell);
52875293

5288-
datums[j++] = CStringGetTextDatum(name);
5294+
if (name)
5295+
{
5296+
nulls[j] = false;
5297+
datums[j++] = CStringGetTextDatum(name);
5298+
}
5299+
else
5300+
nulls[j] = true;
52895301
}
52905302

52915303
MemoryContextSwitchTo(oldcxt);
52925304

5293-
arr = construct_array(datums, list_length(list),
5294-
TEXTOID, -1, false, 'i');
5305+
lb[0] = 1;
5306+
arr = construct_md_array(datums, nulls, 1, &j,
5307+
lb, TEXTOID, -1, false, 'i');
52955308

52965309
MemoryContextDelete(memcxt);
52975310

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy