@@ -151,6 +151,11 @@ neon_try_load(const char *name)
151151{
152152 bool have_slash ;
153153 char * request_name ;
154+ size_t pkglib_path_len ;
155+
156+ #define LIBDIR_PLACEHOLDER_LEN (sizeof("$libdir") - 1)
157+
158+ pkglib_path_len = strlen (pkglib_path );
154159
155160 // add .so suffix if it is not present
156161 if (strstr (name , DLSUFFIX ) == NULL )
@@ -168,19 +173,25 @@ neon_try_load(const char *name)
168173
169174 elog (DEBUG3 , "neon_try_load: request_name: %s, pkglib_path %s" , request_name , pkglib_path );
170175
171- if (strncmp (request_name , "$libdir/" , strlen ( "$libdir/" ) ) == 0 )
176+ if (strncmp (request_name , "$libdir/" , LIBDIR_PLACEHOLDER_LEN + 1 ) == 0 )
172177 {
173- char * new_request_name = psprintf ("%s" , request_name + strlen ( "$libdir/" ) );
178+ char * new_request_name = psprintf ("%s" , request_name + LIBDIR_PLACEHOLDER_LEN + 1 );
174179 pfree (request_name );
175180 request_name = new_request_name ;
176181
177182 elog (DEBUG3 , "neon_try_load: omit $libdir/: %s" , request_name );
178183 }
179184 // if name contains pkglib_path as prefix, strip it and only request the file name
180185 else if (pkglib_path [0 ] != '\0' &&
181- strncmp (request_name , pkglib_path , strlen ( pkglib_path ) ) == 0 )
186+ strncmp (request_name , pkglib_path , pkglib_path_len ) == 0 )
182187 {
183- char * new_request_name = psprintf ("%s" , request_name + strlen (pkglib_path ));
188+ bool have_slash ;
189+ char * new_request_name ;
190+
191+ /* If there is a directory separator, it should be removed. */
192+ have_slash = request_name [pkglib_path_len ] == '/' ;
193+
194+ new_request_name = psprintf ("%s" , request_name + pkglib_path_len + (int )have_slash );
184195 pfree (request_name );
185196 request_name = new_request_name ;
186197
@@ -197,6 +208,8 @@ neon_try_load(const char *name)
197208 elog (DEBUG3 , "neon_try_load: final request_name: %s" , request_name );
198209
199210 download_extension_file_hook (request_name , true);
211+
212+ #undef LIBDIR_PLACEHOLDER_LEN
200213}
201214
202215/*
0 commit comments