@@ -151,6 +151,11 @@ neon_try_load(const char *name)
151
151
{
152
152
bool have_slash ;
153
153
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 );
154
159
155
160
// add .so suffix if it is not present
156
161
if (strstr (name , DLSUFFIX ) == NULL )
@@ -168,19 +173,25 @@ neon_try_load(const char *name)
168
173
169
174
elog (DEBUG3 , "neon_try_load: request_name: %s, pkglib_path %s" , request_name , pkglib_path );
170
175
171
- if (strncmp (request_name , "$libdir/" , strlen ( "$libdir/" ) ) == 0 )
176
+ if (strncmp (request_name , "$libdir/" , LIBDIR_PLACEHOLDER_LEN + 1 ) == 0 )
172
177
{
173
- char * new_request_name = psprintf ("%s" , request_name + strlen ( "$libdir/" ) );
178
+ char * new_request_name = psprintf ("%s" , request_name + LIBDIR_PLACEHOLDER_LEN + 1 );
174
179
pfree (request_name );
175
180
request_name = new_request_name ;
176
181
177
182
elog (DEBUG3 , "neon_try_load: omit $libdir/: %s" , request_name );
178
183
}
179
184
// if name contains pkglib_path as prefix, strip it and only request the file name
180
185
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 )
182
187
{
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 );
184
195
pfree (request_name );
185
196
request_name = new_request_name ;
186
197
@@ -197,6 +208,8 @@ neon_try_load(const char *name)
197
208
elog (DEBUG3 , "neon_try_load: final request_name: %s" , request_name );
198
209
199
210
download_extension_file_hook (request_name , true);
211
+
212
+ #undef LIBDIR_PLACEHOLDER_LEN
200
213
}
201
214
202
215
/*
0 commit comments