Skip to content

Commit 1045655

Browse files
committed
Prevent coredump in current_schemas() if someone has just deleted a
schema that was in our search path.
1 parent 4089d25 commit 1045655

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/backend/utils/adt/name.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.43 2003/03/10 22:28:18 tgl Exp $
15+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.44 2003/04/27 23:22:13 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -246,32 +246,36 @@ current_schema(PG_FUNCTION_ARGS)
246246
if (search_path == NIL)
247247
PG_RETURN_NULL();
248248
nspname = get_namespace_name(lfirsto(search_path));
249+
if (!nspname)
250+
PG_RETURN_NULL(); /* recently-deleted namespace? */
249251
PG_RETURN_DATUM(DirectFunctionCall1(namein, CStringGetDatum(nspname)));
250252
}
251253

252254
Datum
253255
current_schemas(PG_FUNCTION_ARGS)
254256
{
255257
List *search_path = fetch_search_path(PG_GETARG_BOOL(0));
256-
int nnames = length(search_path);
257258
Datum *names;
258259
int i;
259260
ArrayType *array;
260261

261262
/* +1 here is just to avoid palloc(0) error */
262-
names = (Datum *) palloc((nnames + 1) * sizeof(Datum));
263+
names = (Datum *) palloc((length(search_path) + 1) * sizeof(Datum));
263264
i = 0;
264265
while (search_path)
265266
{
266267
char *nspname;
267268

268269
nspname = get_namespace_name(lfirsto(search_path));
269-
names[i] = DirectFunctionCall1(namein, CStringGetDatum(nspname));
270-
i++;
270+
if (nspname) /* watch out for deleted namespace */
271+
{
272+
names[i] = DirectFunctionCall1(namein, CStringGetDatum(nspname));
273+
i++;
274+
}
271275
search_path = lnext(search_path);
272276
}
273277

274-
array = construct_array(names, nnames,
278+
array = construct_array(names, i,
275279
NAMEOID,
276280
NAMEDATALEN, /* sizeof(Name) */
277281
false, /* Name is not by-val */

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