mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Fixed bug #74866 extension_dir = "./ext" now use current directory for base
This commit is contained in:
parent
613102bd67
commit
0782a7fc63
5 changed files with 66 additions and 31 deletions
|
@ -29,8 +29,6 @@ int zend_load_extension(const char *path)
|
|||
{
|
||||
#if ZEND_EXTENSIONS_SUPPORT
|
||||
DL_HANDLE handle;
|
||||
zend_extension *new_extension;
|
||||
zend_extension_version_info *extension_version_info;
|
||||
|
||||
handle = DL_LOAD(path);
|
||||
if (!handle) {
|
||||
|
@ -43,6 +41,22 @@ int zend_load_extension(const char *path)
|
|||
#endif
|
||||
return FAILURE;
|
||||
}
|
||||
return zend_load_extension_handle(handle, path);
|
||||
#else
|
||||
fprintf(stderr, "Extensions are not supported on this platform.\n");
|
||||
/* See http://support.microsoft.com/kb/190351 */
|
||||
#ifdef ZEND_WIN32
|
||||
fflush(stderr);
|
||||
#endif
|
||||
return FAILURE;
|
||||
#endif
|
||||
}
|
||||
|
||||
int zend_load_extension_handle(DL_HANDLE handle, const char *path)
|
||||
{
|
||||
#if ZEND_EXTENSIONS_SUPPORT
|
||||
zend_extension *new_extension;
|
||||
zend_extension_version_info *extension_version_info;
|
||||
|
||||
extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "extension_version_info");
|
||||
if (!extension_version_info) {
|
||||
|
@ -62,7 +76,6 @@ int zend_load_extension(const char *path)
|
|||
return FAILURE;
|
||||
}
|
||||
|
||||
|
||||
/* allow extension to proclaim compatibility with any Zend version */
|
||||
if (extension_version_info->zend_extension_api_no != ZEND_EXTENSION_API_NO &&(!new_extension->api_no_check || new_extension->api_no_check(ZEND_EXTENSION_API_NO) != SUCCESS)) {
|
||||
if (extension_version_info->zend_extension_api_no > ZEND_EXTENSION_API_NO) {
|
||||
|
|
|
@ -145,6 +145,7 @@ void zend_shutdown_extensions(void);
|
|||
|
||||
BEGIN_EXTERN_C()
|
||||
ZEND_API int zend_load_extension(const char *path);
|
||||
ZEND_API int zend_load_extension_handle(DL_HANDLE handle, const char *path);
|
||||
ZEND_API int zend_register_extension(zend_extension *new_extension, DL_HANDLE handle);
|
||||
ZEND_API zend_extension *zend_get_extension(const char *extension_name);
|
||||
ZEND_API size_t zend_extensions_op_array_persist_calc(zend_op_array *op_array);
|
||||
|
|
|
@ -76,6 +76,31 @@ PHPAPI PHP_FUNCTION(dl)
|
|||
|
||||
#if defined(HAVE_LIBDL)
|
||||
|
||||
/* {{{ php_load_shlib
|
||||
*/
|
||||
PHPAPI void *php_load_shlib(char *path, char **errp)
|
||||
{
|
||||
void *handle;
|
||||
char *err;
|
||||
|
||||
handle = DL_LOAD(path);
|
||||
if (!handle) {
|
||||
err = GET_DL_ERROR();
|
||||
#ifdef PHP_WIN32
|
||||
if (err && (*err)) {
|
||||
(*errp)=estrdup(err);
|
||||
LocalFree(err);
|
||||
} else {
|
||||
(*errp) = estrdup("<No message>");
|
||||
}
|
||||
#else
|
||||
(*errp) = estrdup(err);
|
||||
GET_DL_ERROR(); /* free the buffer storing the error */
|
||||
#endif
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
/* {{{ php_load_extension
|
||||
*/
|
||||
PHPAPI int php_load_extension(char *filename, int type, int start_now)
|
||||
|
@ -109,6 +134,7 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now)
|
|||
libpath = estrdup(filename);
|
||||
} else if (extension_dir && extension_dir[0]) {
|
||||
int extension_dir_len = (int)strlen(extension_dir);
|
||||
char *err1, *err2;
|
||||
slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]);
|
||||
/* Try as filename first */
|
||||
if (slash_suffix) {
|
||||
|
@ -117,8 +143,9 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now)
|
|||
spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE */
|
||||
}
|
||||
|
||||
if (VCWD_ACCESS(libpath, F_OK)) {
|
||||
/* If file does not exist, consider as extension name and build file name */
|
||||
handle = php_load_shlib(libpath, &err1);
|
||||
if (!handle) {
|
||||
/* Now, consider 'filename' as extension name and build file name */
|
||||
char *orig_libpath = libpath;
|
||||
|
||||
if (slash_suffix) {
|
||||
|
@ -127,37 +154,23 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now)
|
|||
spprintf(&libpath, 0, "%s%c" PHP_SHLIB_EXT_PREFIX "%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
|
||||
}
|
||||
|
||||
if (VCWD_ACCESS(libpath, F_OK)) {
|
||||
php_error(error_type, "Cannot access dynamic library '%s' (tried : %s, %s)",
|
||||
filename, orig_libpath, libpath);
|
||||
handle = php_load_shlib(libpath, &err2);
|
||||
if (!handle) {
|
||||
php_error_docref(NULL, error_type, "Unable to load dynamic library '%s' (tried: %s (%s), %s (%s))",
|
||||
filename, orig_libpath, err1, libpath, err2);
|
||||
efree(orig_libpath);
|
||||
efree(err1);
|
||||
efree(libpath);
|
||||
efree(err2);
|
||||
return FAILURE;
|
||||
}
|
||||
efree(orig_libpath);
|
||||
efree(err1);
|
||||
}
|
||||
} else {
|
||||
return FAILURE; /* Not full path given or extension_dir is not set */
|
||||
}
|
||||
|
||||
/* load dynamic symbol */
|
||||
handle = DL_LOAD(libpath);
|
||||
if (!handle) {
|
||||
#ifdef PHP_WIN32
|
||||
char *err = GET_DL_ERROR();
|
||||
if (err && (*err != '\0')) {
|
||||
php_error_docref(NULL, error_type, "Unable to load dynamic library '%s' - %s", libpath, err);
|
||||
LocalFree(err);
|
||||
} else {
|
||||
php_error_docref(NULL, error_type, "Unable to load dynamic library '%s' - %s", libpath, "Unknown reason");
|
||||
}
|
||||
#else
|
||||
php_error_docref(NULL, error_type, "Unable to load dynamic library '%s' - %s", libpath, GET_DL_ERROR());
|
||||
GET_DL_ERROR(); /* free the buffer storing the error */
|
||||
#endif
|
||||
efree(libpath);
|
||||
return FAILURE;
|
||||
}
|
||||
efree(libpath);
|
||||
|
||||
get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "get_module");
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
PHPAPI int php_load_extension(char *filename, int type, int start_now);
|
||||
PHPAPI void php_dl(char *file, int type, zval *return_value, int start_now);
|
||||
PHPAPI void *php_load_shlib(char *path, char **errp);
|
||||
|
||||
/* dynamic loading functions */
|
||||
PHPAPI PHP_FUNCTION(dl);
|
||||
|
|
|
@ -362,10 +362,12 @@ static void php_load_zend_extension_cb(void *arg)
|
|||
if (IS_ABSOLUTE_PATH(filename, length)) {
|
||||
zend_load_extension(filename);
|
||||
} else {
|
||||
DL_HANDLE handle;
|
||||
char *libpath;
|
||||
char *extension_dir = INI_STR("extension_dir");
|
||||
int extension_dir_len = (int)strlen(extension_dir);
|
||||
int slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]);
|
||||
char *err1, *err2;
|
||||
/* Try as filename first */
|
||||
if (slash_suffix) {
|
||||
spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */
|
||||
|
@ -373,7 +375,8 @@ static void php_load_zend_extension_cb(void *arg)
|
|||
spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE */
|
||||
}
|
||||
|
||||
if (VCWD_ACCESS(libpath, F_OK)) {
|
||||
handle = (DL_HANDLE)php_load_shlib(libpath, &err1);
|
||||
if (!handle) {
|
||||
/* If file does not exist, consider as extension name and build file name */
|
||||
char *orig_libpath = libpath;
|
||||
|
||||
|
@ -383,18 +386,22 @@ static void php_load_zend_extension_cb(void *arg)
|
|||
spprintf(&libpath, 0, "%s%c" PHP_SHLIB_EXT_PREFIX "%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
|
||||
}
|
||||
|
||||
if (VCWD_ACCESS(libpath, F_OK)) {
|
||||
php_error(E_CORE_WARNING, "Cannot access Zend extension %s (Tried: %s, %s)\n",
|
||||
filename, orig_libpath, libpath);
|
||||
handle = (DL_HANDLE)php_load_shlib(libpath, &err2);
|
||||
if (!handle) {
|
||||
php_error(E_CORE_WARNING, "Failed loading Zend extension '%s' (tried: %s (%s), %s (%s))",
|
||||
filename, orig_libpath, err1, libpath, err2);
|
||||
efree(orig_libpath);
|
||||
efree(err1);
|
||||
efree(libpath);
|
||||
efree(err2);
|
||||
return;
|
||||
}
|
||||
|
||||
efree(orig_libpath);
|
||||
efree(err1);
|
||||
}
|
||||
|
||||
zend_load_extension(libpath);
|
||||
zend_load_extension_handle(handle, libpath);
|
||||
efree(libpath);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue