@@ -77,10 +77,10 @@ PHP_FUNCTION(dl)
77
77
(strncmp (sapi_module .name , "embed" , 5 ) != 0 )
78
78
) {
79
79
#ifdef ZTS
80
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "Not supported in multithreaded Web servers - use extension=%s in your php.ini" , Z_STRVAL_PP ( file ));
80
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Not supported in multithreaded Web servers - use extension=%s in your php.ini" , Z_STRVAL_P ( filename ));
81
81
RETURN_FALSE ;
82
82
#else
83
- php_error_docref (NULL TSRMLS_CC , E_STRICT , "dl() is deprecated - use extension=%s in your php.ini" , Z_STRVAL_PP ( file ));
83
+ php_error_docref (NULL TSRMLS_CC , E_STRICT , "dl() is deprecated - use extension=%s in your php.ini" , Z_STRVAL_P ( filename ));
84
84
#endif
85
85
}
86
86
@@ -97,18 +97,14 @@ PHP_FUNCTION(dl)
97
97
#define USING_ZTS 0
98
98
#endif
99
99
100
- /* {{{ php_dl
101
- */
102
- void php_dl (zval * file , int type , zval * return_value , int start_now TSRMLS_DC )
100
+ PHPAPI int php_load_extension (char * filename , int type , int start_now TSRMLS_DC ) /* {{{ */
103
101
{
104
102
void * handle ;
105
103
char * libpath ;
106
104
zend_module_entry * module_entry ;
107
105
zend_module_entry * (* get_module )(void );
108
106
int error_type ;
109
107
char * extension_dir ;
110
- char * filename ;
111
- int filename_len ;
112
108
113
109
if (type == MODULE_PERSISTENT ) {
114
110
extension_dir = INI_STR ("extension_dir" );
@@ -122,26 +118,24 @@ void php_dl(zval *file, int type, zval *return_value, int start_now TSRMLS_DC)
122
118
error_type = E_CORE_WARNING ;
123
119
}
124
120
125
- filename = Z_STRVAL_P (file );
126
- filename_len = Z_STRLEN_P (file );
127
-
128
- if (extension_dir && extension_dir [0 ]){
129
- int extension_dir_len = strlen (extension_dir );
130
-
121
+ /* Check if passed filename contains directory separators */
122
+ if (strchr (filename , '/' ) != NULL || strchr (filename , DEFAULT_SLASH ) != NULL ) {
123
+ /* Passing modules with full path is not supported for dynamically loaded extensions */
131
124
if (type == MODULE_TEMPORARY ) {
132
- if (strchr (filename , '/' ) != NULL || strchr (filename , DEFAULT_SLASH ) != NULL ) {
133
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "Temporary module name should contain only filename" );
134
- RETURN_FALSE ;
135
- }
125
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Temporary module name should contain only filename" );
126
+ return FAILURE ;
136
127
}
128
+ libpath = estrdup (filename );
129
+ } else if (extension_dir && extension_dir [0 ]) {
130
+ int extension_dir_len = strlen (extension_dir );
137
131
138
132
if (IS_SLASH (extension_dir [extension_dir_len - 1 ])) {
139
133
spprintf (& libpath , 0 , "%s%s" , extension_dir , filename ); /* SAFE */
140
134
} else {
141
135
spprintf (& libpath , 0 , "%s%c%s" , extension_dir , DEFAULT_SLASH , filename ); /* SAFE */
142
136
}
143
137
} else {
144
- libpath = estrndup ( filename , filename_len );
138
+ return FAILURE ; /* Not full path given or extension_dir is not set */
145
139
}
146
140
147
141
/* load dynamic symbol */
@@ -150,9 +144,8 @@ void php_dl(zval *file, int type, zval *return_value, int start_now TSRMLS_DC)
150
144
php_error_docref (NULL TSRMLS_CC , error_type , "Unable to load dynamic library '%s' - %s" , libpath , GET_DL_ERROR ());
151
145
GET_DL_ERROR (); /* free the buffer storing the error */
152
146
efree (libpath );
153
- RETURN_FALSE ;
147
+ return FAILURE ;
154
148
}
155
-
156
149
efree (libpath );
157
150
158
151
get_module = (zend_module_entry * (* )(void )) DL_FETCH_SYMBOL (handle , "get_module" );
@@ -167,8 +160,8 @@ void php_dl(zval *file, int type, zval *return_value, int start_now TSRMLS_DC)
167
160
168
161
if (!get_module ) {
169
162
DL_UNLOAD (handle );
170
- php_error_docref (NULL TSRMLS_CC , error_type , "Invalid library (maybe not a PHP library) '%s' " , filename );
171
- RETURN_FALSE ;
163
+ php_error_docref (NULL TSRMLS_CC , error_type , "Invalid library (maybe not a PHP library) '%s'" , filename );
164
+ return FAILURE ;
172
165
}
173
166
module_entry = get_module ();
174
167
if ((module_entry -> zend_debug != ZEND_DEBUG ) ||
@@ -222,30 +215,47 @@ void php_dl(zval *file, int type, zval *return_value, int start_now TSRMLS_DC)
222
215
name , zend_api , zend_debug , zts ,
223
216
ZEND_MODULE_API_NO , ZEND_DEBUG , USING_ZTS );
224
217
DL_UNLOAD (handle );
225
- RETURN_FALSE ;
218
+ return FAILURE ;
226
219
}
227
220
module_entry -> type = type ;
228
221
module_entry -> module_number = zend_next_free_module ();
229
222
module_entry -> handle = handle ;
230
223
231
224
if ((module_entry = zend_register_module_ex (module_entry TSRMLS_CC )) == NULL ) {
232
225
DL_UNLOAD (handle );
233
- RETURN_FALSE ;
226
+ return FAILURE ;
234
227
}
235
228
236
229
if ((type == MODULE_TEMPORARY || start_now ) && zend_startup_module_ex (module_entry TSRMLS_CC ) == FAILURE ) {
237
230
DL_UNLOAD (handle );
238
- RETURN_FALSE ;
231
+ return FAILURE ;
239
232
}
240
233
241
234
if ((type == MODULE_TEMPORARY || start_now ) && module_entry -> request_startup_func ) {
242
235
if (module_entry -> request_startup_func (type , module_entry -> module_number TSRMLS_CC ) == FAILURE ) {
243
236
php_error_docref (NULL TSRMLS_CC , error_type , "Unable to initialize module '%s'" , module_entry -> name );
244
237
DL_UNLOAD (handle );
245
- RETURN_FALSE ;
238
+ return FAILURE ;
246
239
}
247
240
}
248
- RETURN_TRUE ;
241
+ return SUCCESS ;
242
+ }
243
+ /* }}} */
244
+
245
+ /* {{{ php_dl
246
+ */
247
+ PHPAPI void php_dl (zval * file , int type , zval * return_value , int start_now TSRMLS_DC )
248
+ {
249
+ char * filename ;
250
+
251
+ filename = Z_STRVAL_P (file );
252
+
253
+ /* Load extension */
254
+ if (php_load_extension (filename , type , start_now TSRMLS_CC ) == FAILURE ) {
255
+ RETVAL_FALSE ;
256
+ } else {
257
+ RETVAL_TRUE ;
258
+ }
249
259
}
250
260
/* }}} */
251
261
@@ -256,7 +266,7 @@ PHP_MINFO_FUNCTION(dl)
256
266
257
267
#else
258
268
259
- void php_dl (zval * file , int type , zval * return_value , int start_now TSRMLS_DC )
269
+ PHPAPI void php_dl (zval * file , int type , zval * return_value , int start_now TSRMLS_DC )
260
270
{
261
271
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Cannot dynamically load %s - dynamic modules are not supported" , Z_STRVAL_P (file ));
262
272
RETURN_FALSE ;
0 commit comments