Don't downcase entries within shared_preload_libraries et al.
authorTom Lane <[email protected]>
Tue, 20 Jun 2017 17:02:42 +0000 (13:02 -0400)
committerTom Lane <[email protected]>
Tue, 20 Jun 2017 17:03:29 +0000 (13:03 -0400)
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
src/backend/utils/init/miscinit.c

index a21c689959602a2e0e16f09823d638587ebae787..5fe82400e728e5db9d38bbc5ff7667718c04314f 100644 (file)
@@ -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
index 8d149bf2728cb5c9ee35d90e9481242facbbddda..64b3785d7bb1419c2b97b64d894b21766814948d 100644 (file)
@@ -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);
 }
 
 /*