Skip to content

Commit ddad002

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 2b1971c commit ddad002

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
@@ -3815,7 +3815,10 @@ pg_identify_object_as_address(PG_FUNCTION_ARGS)
38153815
pfree(identity);
38163816

38173817
/* object_names */
3818-
values[1] = PointerGetDatum(strlist_to_textarray(names));
3818+
if (names != NIL)
3819+
values[1] = PointerGetDatum(strlist_to_textarray(names));
3820+
else
3821+
values[1] = PointerGetDatum(construct_empty_array(TEXTOID));
38193822
nulls[1] = false;
38203823

38213824
/* object_args */
@@ -5134,28 +5137,38 @@ strlist_to_textarray(List *list)
51345137
{
51355138
ArrayType *arr;
51365139
Datum *datums;
5140+
bool *nulls;
51375141
int j = 0;
51385142
ListCell *cell;
51395143
MemoryContext memcxt;
51405144
MemoryContext oldcxt;
5145+
int lb[1];
51415146

51425147
memcxt = AllocSetContextCreate(CurrentMemoryContext,
51435148
"strlist to array",
51445149
ALLOCSET_DEFAULT_SIZES);
51455150
oldcxt = MemoryContextSwitchTo(memcxt);
51465151

51475152
datums = palloc(sizeof(text *) * list_length(list));
5153+
nulls = palloc(sizeof(bool) * list_length(list));
51485154
foreach(cell, list)
51495155
{
51505156
char *name = lfirst(cell);
51515157

5152-
datums[j++] = CStringGetTextDatum(name);
5158+
if (name)
5159+
{
5160+
nulls[j] = false;
5161+
datums[j++] = CStringGetTextDatum(name);
5162+
}
5163+
else
5164+
nulls[j++] = true;
51535165
}
51545166

51555167
MemoryContextSwitchTo(oldcxt);
51565168

5157-
arr = construct_array(datums, list_length(list),
5158-
TEXTOID, -1, false, 'i');
5169+
lb[0] = 1;
5170+
arr = construct_md_array(datums, nulls, 1, &j,
5171+
lb, TEXTOID, -1, false, 'i');
51595172
MemoryContextDelete(memcxt);
51605173

51615174
return arr;

0 commit comments

Comments
 (0)