From a69dfe5f40f77d586e8d4d9ecfc39d81612c7dda Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 20 Jun 2017 13:02:42 -0400 Subject: [PATCH] Don't downcase entries within shared_preload_libraries et al. load_libraries(), which processes the various xxx_preload_libraries GUCs, was parsing them using SplitIdentifierString() which isn't really appropriate for values that could be path names: it downcases unquoted text, and it doesn't allow embedded whitespace unless quoted. Use SplitDirectoriesString() instead. That also allows us to simplify load_libraries() a bit, since canonicalize_path() is now done for it. While this definitely seems like a bug fix, it has the potential to break configuration settings that accidentally worked before because of the downcasing behavior. Also, there's an easy workaround for the bug, namely to double-quote troublesome text. Hence, no back-patch. QL Zhuo, tweaked a bit by me Discussion: https://postgr.es/m/CAB-oJtxHVDc3H+Km3CjB9mY1VDzuyaVH_ZYSz7iXcRqCtb93Ew@mail.gmail.com --- src/backend/utils/adt/varlena.c | 4 +++- src/backend/utils/init/miscinit.c | 21 +++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index a21c689959..5fe82400e7 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -3347,7 +3347,9 @@ SplitIdentifierString(char *rawstring, char separator, /* - * SplitDirectoriesString --- parse a string containing directory names + * SplitDirectoriesString --- parse a string containing file/directory names + * + * This works fine on file names too; the function name is historical. * * This is similar to SplitIdentifierString, except that the parsing * rules are meant to handle pathnames instead of identifiers: there is diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 8d149bf272..64b3785d7b 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -1435,12 +1435,12 @@ load_libraries(const char *libraries, const char *gucname, bool restricted) /* Need a modifiable copy of string */ rawstring = pstrdup(libraries); - /* Parse string into list of identifiers */ - if (!SplitIdentifierString(rawstring, ',', &elemlist)) + /* Parse string into list of filename paths */ + if (!SplitDirectoriesString(rawstring, ',', &elemlist)) { /* syntax error in list */ + list_free_deep(elemlist); pfree(rawstring); - list_free(elemlist); ereport(LOG, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("invalid list syntax in parameter \"%s\"", @@ -1450,28 +1450,25 @@ load_libraries(const char *libraries, const char *gucname, bool restricted) foreach(l, elemlist) { - char *tok = (char *) lfirst(l); - char *filename; + /* Note that filename was already canonicalized */ + char *filename = (char *) lfirst(l); + char *expanded = NULL; - filename = pstrdup(tok); - canonicalize_path(filename); /* If restricting, insert $libdir/plugins if not mentioned already */ if (restricted && first_dir_separator(filename) == NULL) { - char *expanded; - expanded = psprintf("$libdir/plugins/%s", filename); - pfree(filename); filename = expanded; } load_file(filename, restricted); ereport(DEBUG1, (errmsg("loaded library \"%s\"", filename))); - pfree(filename); + if (expanded) + pfree(expanded); } + list_free_deep(elemlist); pfree(rawstring); - list_free(elemlist); } /* -- 2.40.0