mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-31 14:57:22 +02:00
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
This commit is contained in:
parent
fbec6fa38a
commit
728ac262d1
@ -3887,7 +3887,10 @@ pg_identify_object_as_address(PG_FUNCTION_ARGS)
|
|||||||
pfree(identity);
|
pfree(identity);
|
||||||
|
|
||||||
/* object_names */
|
/* object_names */
|
||||||
|
if (names != NIL)
|
||||||
values[1] = PointerGetDatum(strlist_to_textarray(names));
|
values[1] = PointerGetDatum(strlist_to_textarray(names));
|
||||||
|
else
|
||||||
|
values[1] = PointerGetDatum(construct_empty_array(TEXTOID));
|
||||||
nulls[1] = false;
|
nulls[1] = false;
|
||||||
|
|
||||||
/* object_args */
|
/* object_args */
|
||||||
@ -5209,10 +5212,12 @@ strlist_to_textarray(List *list)
|
|||||||
{
|
{
|
||||||
ArrayType *arr;
|
ArrayType *arr;
|
||||||
Datum *datums;
|
Datum *datums;
|
||||||
|
bool *nulls;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
ListCell *cell;
|
ListCell *cell;
|
||||||
MemoryContext memcxt;
|
MemoryContext memcxt;
|
||||||
MemoryContext oldcxt;
|
MemoryContext oldcxt;
|
||||||
|
int lb[1];
|
||||||
|
|
||||||
/* Work in a temp context; easier than individually pfree'ing the Datums */
|
/* Work in a temp context; easier than individually pfree'ing the Datums */
|
||||||
memcxt = AllocSetContextCreate(CurrentMemoryContext,
|
memcxt = AllocSetContextCreate(CurrentMemoryContext,
|
||||||
@ -5221,18 +5226,26 @@ strlist_to_textarray(List *list)
|
|||||||
oldcxt = MemoryContextSwitchTo(memcxt);
|
oldcxt = MemoryContextSwitchTo(memcxt);
|
||||||
|
|
||||||
datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
|
datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
|
||||||
|
nulls = palloc(sizeof(bool) * list_length(list));
|
||||||
|
|
||||||
foreach(cell, list)
|
foreach(cell, list)
|
||||||
{
|
{
|
||||||
char *name = lfirst(cell);
|
char *name = lfirst(cell);
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
{
|
||||||
|
nulls[j] = false;
|
||||||
datums[j++] = CStringGetTextDatum(name);
|
datums[j++] = CStringGetTextDatum(name);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
nulls[j] = true;
|
||||||
|
}
|
||||||
|
|
||||||
MemoryContextSwitchTo(oldcxt);
|
MemoryContextSwitchTo(oldcxt);
|
||||||
|
|
||||||
arr = construct_array(datums, list_length(list),
|
lb[0] = 1;
|
||||||
TEXTOID, -1, false, 'i');
|
arr = construct_md_array(datums, nulls, 1, &j,
|
||||||
|
lb, TEXTOID, -1, false, 'i');
|
||||||
|
|
||||||
MemoryContextDelete(memcxt);
|
MemoryContextDelete(memcxt);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user