Don't strip $libdir from LOAD command
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 4 Jun 2025 09:21:24 +0000 (11:21 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 4 Jun 2025 09:38:12 +0000 (11:38 +0200)
Commit 4f7f7b03758 implemented the extension_control_path GUC, and to
make it work it was decided that we should strip the $libdir/ on
module_pathname from .control files, so that extensions don't need to
worry about this change.

This strip logic was implemented on expand_dynamic_library_name()
which works fine when executing the SQL functions from extensions, but
this function is also called when the LOAD command is executed, and
since the user may explicitly pass the $libdir prefix on LOAD
parameter, we should not strip in this case.

This commit fixes this issue by moving the strip logic from
expand_dynamic_library_name() to load_external_function() that is
called when the running the SQL script from extensions.

Reported-by: Evan Si <evsi@amazon.com>
Author: Matheus Alcantara <matheusssilv97@gmail.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Rahila Syed <rahilasyed90@gmail.com>
Bug: #18920
Discussion: https://www.postgresql.org/message-id/flat/18920-b350b1c0a30af006%40postgresql.org

src/backend/utils/fmgr/dfmgr.c

index 603632581d04a716263e5a70e41e64f486102179..4bb84ff70870f64fae8acdda1b6096071030740b 100644 (file)
@@ -99,6 +99,14 @@ load_external_function(const char *filename, const char *funcname,
    void       *lib_handle;
    void       *retval;
 
+   /*
+    * If the value starts with "$libdir/", strip that.  This is because many
+    * extensions have hardcoded '$libdir/foo' as their library name, which
+    * prevents using the path.
+    */
+   if (strncmp(filename, "$libdir/", 8) == 0)
+       filename += 8;
+
    /* Expand the possibly-abbreviated filename to an exact path name */
    fullname = expand_dynamic_library_name(filename);
 
@@ -456,14 +464,6 @@ expand_dynamic_library_name(const char *name)
 
    Assert(name);
 
-   /*
-    * If the value starts with "$libdir/", strip that.  This is because many
-    * extensions have hardcoded '$libdir/foo' as their library name, which
-    * prevents using the path.
-    */
-   if (strncmp(name, "$libdir/", 8) == 0)
-       name += 8;
-
    have_slash = (first_dir_separator(name) != NULL);
 
    if (!have_slash)