Skip to content

Commit 728ac26

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 fbec6fa commit 728ac26

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
@@ -3887,7 +3887,10 @@ pg_identify_object_as_address(PG_FUNCTION_ARGS)
38873887
pfree(identity);
38883888

38893889
/* object_names */
3890-
values[1] = PointerGetDatum(strlist_to_textarray(names));
3890+
if (names != NIL)
3891+
values[1] = PointerGetDatum(strlist_to_textarray(names));
3892+
else
3893+
values[1] = PointerGetDatum(construct_empty_array(TEXTOID));
38913894
nulls[1] = false;
38923895

38933896
/* object_args */
@@ -5209,10 +5212,12 @@ strlist_to_textarray(List *list)
52095212
{
52105213
ArrayType *arr;
52115214
Datum *datums;
5215+
bool *nulls;
52125216
int j = 0;
52135217
ListCell *cell;
52145218
MemoryContext memcxt;
52155219
MemoryContext oldcxt;
5220+
int lb[1];
52165221

52175222
/* Work in a temp context; easier than individually pfree'ing the Datums */
52185223
memcxt = AllocSetContextCreate(CurrentMemoryContext,
@@ -5221,18 +5226,26 @@ strlist_to_textarray(List *list)
52215226
oldcxt = MemoryContextSwitchTo(memcxt);
52225227

52235228
datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
5229+
nulls = palloc(sizeof(bool) * list_length(list));
52245230

52255231
foreach(cell, list)
52265232
{
52275233
char *name = lfirst(cell);
52285234

5229-
datums[j++] = CStringGetTextDatum(name);
5235+
if (name)
5236+
{
5237+
nulls[j] = false;
5238+
datums[j++] = CStringGetTextDatum(name);
5239+
}
5240+
else
5241+
nulls[j] = true;
52305242
}
52315243

52325244
MemoryContextSwitchTo(oldcxt);
52335245

5234-
arr = construct_array(datums, list_length(list),
5235-
TEXTOID, -1, false, 'i');
5246+
lb[0] = 1;
5247+
arr = construct_md_array(datums, nulls, 1, &j,
5248+
lb, TEXTOID, -1, false, 'i');
52365249

52375250
MemoryContextDelete(memcxt);
52385251

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